ea1e4c38fa
This reverts commitcdfc94f4e9
, reversing changes made to2051cd3e1c
. Conflicts: config/config.go config/config_test.go config/etc_hosts.go config/etcd.go config/file.go config/fleet.go config/oem.go config/unit.go config/update.go config/user.go initialize/config.go initialize/config_test.go initialize/env.go initialize/manage_etc_hosts.go initialize/workspace.go system/env.go system/etc_hosts_test.go system/etcd.go system/etcd_test.go system/fleet.go system/fleet_test.go system/oem.go system/oem_test.go system/systemd.go system/update.go system/update_test.go test
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
/*
|
|
Copyright 2014 CoreOS, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package initialize
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseHeaderCRLF(t *testing.T) {
|
|
configs := []string{
|
|
"#cloud-config\nfoo: bar",
|
|
"#cloud-config\r\nfoo: bar",
|
|
}
|
|
|
|
for i, config := range configs {
|
|
_, err := ParseUserData(config)
|
|
if err != nil {
|
|
t.Errorf("Failed parsing config %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
scripts := []string{
|
|
"#!bin/bash\necho foo",
|
|
"#!bin/bash\r\necho foo",
|
|
}
|
|
|
|
for i, script := range scripts {
|
|
_, err := ParseUserData(script)
|
|
if err != nil {
|
|
t.Errorf("Failed parsing script %d: %v", i, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseConfigCRLF(t *testing.T) {
|
|
contents := "#cloud-config\r\nhostname: foo\r\nssh_authorized_keys:\r\n - foobar\r\n"
|
|
ud, err := ParseUserData(contents)
|
|
if err != nil {
|
|
t.Fatalf("Failed parsing config: %v", err)
|
|
}
|
|
|
|
cfg := ud.(*CloudConfig)
|
|
|
|
if cfg.Hostname != "foo" {
|
|
t.Error("Failed parsing hostname from config")
|
|
}
|
|
|
|
if len(cfg.SSHAuthorizedKeys) != 1 {
|
|
t.Error("Parsed incorrect number of SSH keys")
|
|
}
|
|
}
|
|
|
|
func TestParseConfigEmpty(t *testing.T) {
|
|
i, e := ParseUserData(``)
|
|
if i != nil {
|
|
t.Error("ParseUserData of empty string returned non-nil unexpectedly")
|
|
} else if e != nil {
|
|
t.Error("ParseUserData of empty string returned error unexpectedly")
|
|
}
|
|
}
|