2015-01-25 06:32:33 +03:00
|
|
|
// Copyright 2015 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.
|
2014-10-18 02:36:22 +04:00
|
|
|
|
2014-09-22 06:22:13 +04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2014-12-21 10:26:05 +03:00
|
|
|
"regexp"
|
2014-09-22 03:46:58 +04:00
|
|
|
"strings"
|
2014-09-22 06:22:13 +04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-12-21 04:57:15 +03:00
|
|
|
func TestNewCloudConfig(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
contents string
|
|
|
|
|
|
|
|
config CloudConfig
|
|
|
|
}{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite_files:\n - path: underscore",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{Path: "underscore"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite-files:\n - path: hyphen",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{Path: "hyphen"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\ncoreos:\n update:\n reboot-strategy: off",
|
|
|
|
config: CloudConfig{CoreOS: CoreOS{Update: Update{RebootStrategy: "off"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\ncoreos:\n update:\n reboot-strategy: false",
|
|
|
|
config: CloudConfig{CoreOS: CoreOS{Update: Update{RebootStrategy: "false"}}},
|
|
|
|
},
|
2014-12-21 22:16:42 +03:00
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite_files:\n - permissions: 0744",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{RawFilePermissions: "0744"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite_files:\n - permissions: 744",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{RawFilePermissions: "744"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite_files:\n - permissions: '0744'",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{RawFilePermissions: "0744"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
contents: "#cloud-config\nwrite_files:\n - permissions: '744'",
|
|
|
|
config: CloudConfig{WriteFiles: []File{File{RawFilePermissions: "744"}}},
|
|
|
|
},
|
2014-12-21 04:57:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
config, err := NewCloudConfig(tt.contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("bad error (test case #%d): want %v, got %s", i, nil, err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(&tt.config, config) {
|
|
|
|
t.Errorf("bad config (test case #%d): want %#v, got %#v", i, tt.config, config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 06:22:13 +04:00
|
|
|
func TestIsZero(t *testing.T) {
|
2014-12-21 04:47:17 +03:00
|
|
|
tests := []struct {
|
|
|
|
c interface{}
|
|
|
|
|
2014-09-22 06:22:13 +04:00
|
|
|
empty bool
|
|
|
|
}{
|
|
|
|
{struct{}{}, true},
|
|
|
|
{struct{ a, b string }{}, true},
|
|
|
|
{struct{ A, b string }{}, true},
|
|
|
|
{struct{ A, B string }{}, true},
|
|
|
|
{struct{ A string }{A: "hello"}, false},
|
|
|
|
{struct{ A int }{}, true},
|
|
|
|
{struct{ A int }{A: 1}, false},
|
2014-12-21 04:47:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2014-09-22 06:22:13 +04:00
|
|
|
if empty := IsZero(tt.c); tt.empty != empty {
|
2014-10-23 22:46:08 +04:00
|
|
|
t.Errorf("bad result (%q): want %t, got %t", tt.c, tt.empty, empty)
|
2014-09-22 06:22:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 06:04:43 +03:00
|
|
|
func TestAssertStructValid(t *testing.T) {
|
2014-12-21 04:47:17 +03:00
|
|
|
tests := []struct {
|
|
|
|
c interface{}
|
|
|
|
|
2014-09-22 06:22:13 +04:00
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{struct{}{}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b string `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b string `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{A: "1", b: "2"}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b string `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{A: "1", b: "hello"}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b string `valid:"^1|2$"`
|
|
|
|
}{A: "hello", b: "2"}, &ErrorValid{Value: "hello", Field: "A", Valid: "^1|2$"}},
|
2014-09-22 06:22:13 +04:00
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b int `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b int `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{A: 1, b: 2}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b int `valid:"^1|2$"`
|
2014-09-22 06:22:13 +04:00
|
|
|
}{A: 1, b: 9}, nil},
|
|
|
|
{struct {
|
2014-12-21 10:26:05 +03:00
|
|
|
A, b int `valid:"^1|2$"`
|
|
|
|
}{A: 9, b: 2}, &ErrorValid{Value: "9", Field: "A", Valid: "^1|2$"}},
|
2014-09-22 06:22:13 +04:00
|
|
|
}
|
2014-09-22 03:46:58 +04:00
|
|
|
|
2014-12-21 04:47:17 +03:00
|
|
|
for _, tt := range tests {
|
|
|
|
if err := AssertStructValid(tt.c); !reflect.DeepEqual(tt.err, err) {
|
|
|
|
t.Errorf("bad result (%q): want %q, got %q", tt.c, tt.err, err)
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-21 10:26:05 +03:00
|
|
|
func TestConfigCompile(t *testing.T) {
|
|
|
|
tests := []interface{}{
|
|
|
|
Etcd{},
|
|
|
|
File{},
|
|
|
|
Flannel{},
|
|
|
|
Fleet{},
|
|
|
|
Locksmith{},
|
|
|
|
OEM{},
|
|
|
|
Unit{},
|
|
|
|
Update{},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
ttt := reflect.TypeOf(tt)
|
|
|
|
for i := 0; i < ttt.NumField(); i++ {
|
|
|
|
ft := ttt.Field(i)
|
|
|
|
if !isFieldExported(ft) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := regexp.Compile(ft.Tag.Get("valid")); err != nil {
|
|
|
|
t.Errorf("bad regexp(%s.%s): want %v, got %s", ttt.Name(), ft.Name, nil, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
func TestCloudConfigUnknownKeys(t *testing.T) {
|
|
|
|
contents := `
|
2015-11-25 14:21:09 +03:00
|
|
|
coreos:
|
2014-09-22 03:46:58 +04:00
|
|
|
etcd:
|
|
|
|
discovery: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
|
|
|
coreos_unknown:
|
|
|
|
foo: "bar"
|
|
|
|
section_unknown:
|
|
|
|
dunno:
|
|
|
|
something
|
|
|
|
bare_unknown:
|
|
|
|
bar
|
|
|
|
write_files:
|
|
|
|
- content: fun
|
|
|
|
path: /var/party
|
|
|
|
file_unknown: nofun
|
|
|
|
users:
|
|
|
|
- name: fry
|
|
|
|
passwd: somehash
|
|
|
|
user_unknown: philip
|
|
|
|
hostname:
|
|
|
|
foo
|
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error instantiating CloudConfig with unknown keys: %v", err)
|
|
|
|
}
|
|
|
|
if cfg.Hostname != "foo" {
|
|
|
|
t.Fatalf("hostname not correctly set when invalid keys are present")
|
|
|
|
}
|
2014-12-21 23:14:23 +03:00
|
|
|
if cfg.CoreOS.Etcd.Discovery != "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877" {
|
2014-09-22 03:46:58 +04:00
|
|
|
t.Fatalf("etcd section not correctly set when invalid keys are present")
|
|
|
|
}
|
|
|
|
if len(cfg.WriteFiles) < 1 || cfg.WriteFiles[0].Content != "fun" || cfg.WriteFiles[0].Path != "/var/party" {
|
|
|
|
t.Fatalf("write_files section not correctly set when invalid keys are present")
|
|
|
|
}
|
|
|
|
if len(cfg.Users) < 1 || cfg.Users[0].Name != "fry" || cfg.Users[0].PasswordHash != "somehash" {
|
|
|
|
t.Fatalf("users section not correctly set when invalid keys are present")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that the parsing of a cloud config file "generally works"
|
|
|
|
func TestCloudConfigEmpty(t *testing.T) {
|
|
|
|
cfg, err := NewCloudConfig("")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error :%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
keys := cfg.SSHAuthorizedKeys
|
|
|
|
if len(keys) != 0 {
|
|
|
|
t.Error("Parsed incorrect number of SSH keys")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.WriteFiles) != 0 {
|
|
|
|
t.Error("Expected zero WriteFiles")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Hostname != "" {
|
|
|
|
t.Errorf("Expected hostname to be empty, got '%s'", cfg.Hostname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that the parsing of a cloud config file "generally works"
|
|
|
|
func TestCloudConfig(t *testing.T) {
|
|
|
|
contents := `
|
2015-11-25 14:21:09 +03:00
|
|
|
coreos:
|
2014-09-22 03:46:58 +04:00
|
|
|
etcd:
|
|
|
|
discovery: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
|
|
|
update:
|
2014-11-03 23:09:52 +03:00
|
|
|
reboot_strategy: reboot
|
2014-09-22 03:46:58 +04:00
|
|
|
units:
|
|
|
|
- name: 50-eth0.network
|
|
|
|
runtime: yes
|
|
|
|
content: '[Match]
|
2015-11-25 14:21:09 +03:00
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
Name=eth47
|
2015-11-25 14:21:09 +03:00
|
|
|
|
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
[Network]
|
2015-11-25 14:21:09 +03:00
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
Address=10.209.171.177/19
|
2015-11-25 14:21:09 +03:00
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
'
|
|
|
|
oem:
|
|
|
|
id: rackspace
|
|
|
|
name: Rackspace Cloud Servers
|
2014-11-03 23:09:52 +03:00
|
|
|
version_id: 168.0.0
|
|
|
|
home_url: https://www.rackspace.com/cloud/servers/
|
|
|
|
bug_report_url: https://github.com/coreos/coreos-overlay
|
2014-09-22 03:46:58 +04:00
|
|
|
ssh_authorized_keys:
|
|
|
|
- foobar
|
|
|
|
- foobaz
|
|
|
|
write_files:
|
|
|
|
- content: |
|
|
|
|
penny
|
|
|
|
elroy
|
|
|
|
path: /etc/dogepack.conf
|
|
|
|
permissions: '0644'
|
|
|
|
owner: root:dogepack
|
|
|
|
hostname: trontastic
|
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error :%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
keys := cfg.SSHAuthorizedKeys
|
|
|
|
if len(keys) != 2 {
|
|
|
|
t.Error("Parsed incorrect number of SSH keys")
|
|
|
|
} else if keys[0] != "foobar" {
|
|
|
|
t.Error("Expected first SSH key to be 'foobar'")
|
|
|
|
} else if keys[1] != "foobaz" {
|
|
|
|
t.Error("Expected first SSH key to be 'foobaz'")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.WriteFiles) != 1 {
|
|
|
|
t.Error("Failed to parse correct number of write_files")
|
|
|
|
} else {
|
|
|
|
wf := cfg.WriteFiles[0]
|
|
|
|
if wf.Content != "penny\nelroy\n" {
|
|
|
|
t.Errorf("WriteFile has incorrect contents '%s'", wf.Content)
|
|
|
|
}
|
|
|
|
if wf.Encoding != "" {
|
|
|
|
t.Errorf("WriteFile has incorrect encoding %s", wf.Encoding)
|
|
|
|
}
|
|
|
|
if wf.RawFilePermissions != "0644" {
|
|
|
|
t.Errorf("WriteFile has incorrect permissions %s", wf.RawFilePermissions)
|
|
|
|
}
|
|
|
|
if wf.Path != "/etc/dogepack.conf" {
|
|
|
|
t.Errorf("WriteFile has incorrect path %s", wf.Path)
|
|
|
|
}
|
|
|
|
if wf.Owner != "root:dogepack" {
|
|
|
|
t.Errorf("WriteFile has incorrect owner %s", wf.Owner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-21 23:14:23 +03:00
|
|
|
if len(cfg.CoreOS.Units) != 1 {
|
2014-09-22 03:46:58 +04:00
|
|
|
t.Error("Failed to parse correct number of units")
|
|
|
|
} else {
|
2014-12-21 23:14:23 +03:00
|
|
|
u := cfg.CoreOS.Units[0]
|
2014-09-22 03:46:58 +04:00
|
|
|
expect := `[Match]
|
|
|
|
Name=eth47
|
|
|
|
|
|
|
|
[Network]
|
|
|
|
Address=10.209.171.177/19
|
|
|
|
`
|
|
|
|
if u.Content != expect {
|
|
|
|
t.Errorf("Unit has incorrect contents '%s'.\nExpected '%s'.", u.Content, expect)
|
|
|
|
}
|
|
|
|
if u.Runtime != true {
|
|
|
|
t.Errorf("Unit has incorrect runtime value")
|
|
|
|
}
|
|
|
|
if u.Name != "50-eth0.network" {
|
|
|
|
t.Errorf("Unit has incorrect name %s", u.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-21 23:14:23 +03:00
|
|
|
if cfg.CoreOS.OEM.ID != "rackspace" {
|
|
|
|
t.Errorf("Failed parsing coreos.oem. Expected ID 'rackspace', got %q.", cfg.CoreOS.OEM.ID)
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Hostname != "trontastic" {
|
|
|
|
t.Errorf("Failed to parse hostname")
|
|
|
|
}
|
2014-12-21 23:14:23 +03:00
|
|
|
if cfg.CoreOS.Update.RebootStrategy != "reboot" {
|
2014-09-22 03:46:58 +04:00
|
|
|
t.Errorf("Failed to parse locksmith strategy")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that our interface conversion doesn't panic
|
|
|
|
func TestCloudConfigKeysNotList(t *testing.T) {
|
|
|
|
contents := `
|
|
|
|
ssh_authorized_keys:
|
|
|
|
- foo: bar
|
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
keys := cfg.SSHAuthorizedKeys
|
|
|
|
if len(keys) != 0 {
|
|
|
|
t.Error("Parsed incorrect number of SSH keys")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudConfigSerializationHeader(t *testing.T) {
|
|
|
|
cfg, _ := NewCloudConfig("")
|
|
|
|
contents := cfg.String()
|
|
|
|
header := strings.SplitN(contents, "\n", 2)[0]
|
|
|
|
if header != "#cloud-config" {
|
|
|
|
t.Fatalf("Serialized config did not have expected header")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudConfigUsers(t *testing.T) {
|
|
|
|
contents := `
|
|
|
|
users:
|
|
|
|
- name: elroy
|
|
|
|
passwd: somehash
|
2014-11-03 23:09:52 +03:00
|
|
|
ssh_authorized_keys:
|
2014-09-22 03:46:58 +04:00
|
|
|
- somekey
|
|
|
|
gecos: arbitrary comment
|
|
|
|
homedir: /home/place
|
2014-11-03 23:09:52 +03:00
|
|
|
no_create_home: yes
|
2015-11-25 14:21:09 +03:00
|
|
|
lock_passwd: false
|
2014-11-03 23:09:52 +03:00
|
|
|
primary_group: things
|
2014-09-22 03:46:58 +04:00
|
|
|
groups:
|
|
|
|
- ping
|
|
|
|
- pong
|
2014-11-03 23:09:52 +03:00
|
|
|
no_user_group: true
|
2014-09-22 03:46:58 +04:00
|
|
|
system: y
|
2014-11-03 23:09:52 +03:00
|
|
|
no_log_init: True
|
2015-03-07 01:16:19 +03:00
|
|
|
shell: /bin/sh
|
2014-09-22 03:46:58 +04:00
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.Users) != 1 {
|
2014-10-23 22:46:08 +04:00
|
|
|
t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
user := cfg.Users[0]
|
|
|
|
|
|
|
|
if user.Name != "elroy" {
|
|
|
|
t.Errorf("User name is %q, expected 'elroy'", user.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.PasswordHash != "somehash" {
|
|
|
|
t.Errorf("User passwd is %q, expected 'somehash'", user.PasswordHash)
|
|
|
|
}
|
|
|
|
|
|
|
|
if keys := user.SSHAuthorizedKeys; len(keys) != 1 {
|
|
|
|
t.Errorf("Parsed %d ssh keys, expected 1", len(keys))
|
|
|
|
} else {
|
|
|
|
key := user.SSHAuthorizedKeys[0]
|
|
|
|
if key != "somekey" {
|
|
|
|
t.Errorf("User SSH key is %q, expected 'somekey'", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.GECOS != "arbitrary comment" {
|
|
|
|
t.Errorf("Failed to parse gecos field, got %q", user.GECOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Homedir != "/home/place" {
|
|
|
|
t.Errorf("Failed to parse homedir field, got %q", user.Homedir)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !user.NoCreateHome {
|
2014-11-03 23:09:52 +03:00
|
|
|
t.Errorf("Failed to parse no_create_home field")
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if user.PrimaryGroup != "things" {
|
2014-11-03 23:09:52 +03:00
|
|
|
t.Errorf("Failed to parse primary_group field, got %q", user.PrimaryGroup)
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(user.Groups) != 2 {
|
|
|
|
t.Errorf("Failed to parse 2 goups, got %d", len(user.Groups))
|
|
|
|
} else {
|
|
|
|
if user.Groups[0] != "ping" {
|
|
|
|
t.Errorf("First group was %q, not expected value 'ping'", user.Groups[0])
|
|
|
|
}
|
|
|
|
if user.Groups[1] != "pong" {
|
|
|
|
t.Errorf("First group was %q, not expected value 'pong'", user.Groups[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !user.NoUserGroup {
|
2014-11-03 23:09:52 +03:00
|
|
|
t.Errorf("Failed to parse no_user_group field")
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !user.System {
|
|
|
|
t.Errorf("Failed to parse system field")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !user.NoLogInit {
|
2014-11-03 23:09:52 +03:00
|
|
|
t.Errorf("Failed to parse no_log_init field")
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
2015-03-07 01:16:19 +03:00
|
|
|
|
|
|
|
if user.Shell != "/bin/sh" {
|
|
|
|
t.Errorf("Failed to parse shell field, got %q", user.Shell)
|
|
|
|
}
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudConfigUsersGithubUser(t *testing.T) {
|
|
|
|
|
|
|
|
contents := `
|
|
|
|
users:
|
|
|
|
- name: elroy
|
2014-11-03 23:09:52 +03:00
|
|
|
coreos_ssh_import_github: bcwaldon
|
2014-09-22 03:46:58 +04:00
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.Users) != 1 {
|
2014-10-23 22:46:08 +04:00
|
|
|
t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
user := cfg.Users[0]
|
|
|
|
|
|
|
|
if user.Name != "elroy" {
|
|
|
|
t.Errorf("User name is %q, expected 'elroy'", user.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.SSHImportGithubUser != "bcwaldon" {
|
|
|
|
t.Errorf("github user is %q, expected 'bcwaldon'", user.SSHImportGithubUser)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudConfigUsersSSHImportURL(t *testing.T) {
|
|
|
|
contents := `
|
|
|
|
users:
|
|
|
|
- name: elroy
|
2014-11-03 23:09:52 +03:00
|
|
|
coreos_ssh_import_url: https://token:x-auth-token@github.enterprise.com/api/v3/polvi/keys
|
2014-09-22 03:46:58 +04:00
|
|
|
`
|
|
|
|
cfg, err := NewCloudConfig(contents)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Encountered unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cfg.Users) != 1 {
|
2014-10-23 22:46:08 +04:00
|
|
|
t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
|
2014-09-22 03:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
user := cfg.Users[0]
|
|
|
|
|
|
|
|
if user.Name != "elroy" {
|
|
|
|
t.Errorf("User name is %q, expected 'elroy'", user.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.SSHImportURL != "https://token:x-auth-token@github.enterprise.com/api/v3/polvi/keys" {
|
|
|
|
t.Errorf("ssh import url is %q, expected 'https://token:x-auth-token@github.enterprise.com/api/v3/polvi/keys'", user.SSHImportURL)
|
|
|
|
}
|
|
|
|
}
|