github.com/coreos/mantle@v0.13.0/platform/conf/conf_test.go (about) 1 // Copyright 2015 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package conf 16 17 import ( 18 "net" 19 "strings" 20 "testing" 21 22 "github.com/coreos/mantle/network" 23 ) 24 25 func TestConfCopyKey(t *testing.T) { 26 agent, err := network.NewSSHAgent(&net.Dialer{}) 27 if err != nil { 28 t.Fatalf("NewSSHAgent failed: %v", err) 29 } 30 31 keys, err := agent.List() 32 if err != nil { 33 t.Fatalf("agent.List failed: %v", err) 34 } 35 36 tests := []*UserData{ 37 ContainerLinuxConfig(""), 38 Ignition(`{ "ignition": { "version": "2.2.0" } }`), 39 Ignition(`{ "ignition": { "version": "2.1.0" } }`), 40 Ignition(`{ "ignition": { "version": "2.0.0" } }`), 41 Ignition(`{ "ignitionVersion": 1 }`), 42 CloudConfig("#cloud-config"), 43 } 44 45 for i, tt := range tests { 46 conf, err := tt.Render("") 47 if err != nil { 48 t.Errorf("failed to parse config %d: %v", i, err) 49 continue 50 } 51 52 conf.CopyKeys(keys) 53 54 str := conf.String() 55 56 if !strings.Contains(str, "ssh-rsa ") || !strings.Contains(str, " core@default") { 57 t.Errorf("ssh public key not found in config %d: %s", i, str) 58 continue 59 } 60 } 61 }