github.com/didip/deis@v1.4.1/deisctl/config/config_test.go (about) 1 package config 2 3 import ( 4 "encoding/base64" 5 "io/ioutil" 6 "os" 7 "testing" 8 ) 9 10 // TestConfigSSHPrivateKey ensures private keys are base64 encoded from file path 11 func TestConfigSSHPrivateKey(t *testing.T) { 12 13 f, err := writeTempFile("private-key") 14 if err != nil { 15 t.Fatal(err) 16 } 17 18 val, err := valueForPath("/deis/platform/sshPrivateKey", f.Name()) 19 if err != nil { 20 t.Fatal(err) 21 } 22 23 encoded := base64.StdEncoding.EncodeToString([]byte("private-key")) 24 25 if val != encoded { 26 t.Fatalf("expected: %v, got: %v", encoded, val) 27 } 28 } 29 30 func TestConfigRouterKey(t *testing.T) { 31 32 f, err := writeTempFile("router-key") 33 if err != nil { 34 t.Fatal(err) 35 } 36 37 val, err := valueForPath("/deis/router/sslKey", f.Name()) 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 if val != "router-key" { 43 t.Fatalf("expected: router-key, got: %v", val) 44 } 45 46 } 47 48 func TestConfigRouterCert(t *testing.T) { 49 50 f, err := writeTempFile("router-cert") 51 if err != nil { 52 t.Fatal(err) 53 } 54 55 val, err := valueForPath("/deis/router/sslCert", f.Name()) 56 if err != nil { 57 t.Fatal(err) 58 } 59 60 if val != "router-cert" { 61 t.Fatalf("expected: router-cert, got: %v", val) 62 } 63 64 } 65 66 func writeTempFile(data string) (*os.File, error) { 67 f, err := ioutil.TempFile("", "deisctl") 68 if err != nil { 69 return nil, err 70 } 71 72 f.Write([]byte(data)) 73 defer f.Close() 74 75 return f, nil 76 }