2019-02-10 19:00:16 +00:00
|
|
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
2019-02-21 20:48:45 +00:00
|
|
|
// Use of this source code is governed by the Drone Non-Commercial License
|
|
|
|
// that can be found in the LICENSE file.
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnmarshalSecrets(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
from string
|
|
|
|
want []*Secret
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
from: "[ mysql_username, mysql_password]",
|
|
|
|
want: []*Secret{
|
|
|
|
{
|
|
|
|
Source: "mysql_username",
|
|
|
|
Target: "mysql_username",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "mysql_password",
|
|
|
|
Target: "mysql_password",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: "[ { source: mysql_prod_username, target: mysql_username } ]",
|
|
|
|
want: []*Secret{
|
|
|
|
{
|
|
|
|
Source: "mysql_prod_username",
|
|
|
|
Target: "mysql_username",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: "[ { source: mysql_prod_username, target: mysql_username }, { source: redis_username, target: redis_username } ]",
|
|
|
|
want: []*Secret{
|
|
|
|
{
|
|
|
|
Source: "mysql_prod_username",
|
|
|
|
Target: "mysql_username",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "redis_username",
|
|
|
|
Target: "redis_username",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testdata {
|
|
|
|
in := []byte(test.from)
|
|
|
|
got := Secrets{}
|
|
|
|
err := yaml.Unmarshal(in, &got)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
} else if !reflect.DeepEqual(test.want, got.Secrets) {
|
|
|
|
t.Errorf("got secret %v want %v", got.Secrets, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|