github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/github/yaml/secrets_test.go (about) 1 package yaml 2 3 import ( 4 "github.com/google/go-cmp/cmp" 5 "gopkg.in/yaml.v3" 6 "testing" 7 ) 8 9 func TestSecrets(t *testing.T) { 10 tests := []struct { 11 yaml string 12 want Secrets 13 }{ 14 // string value 15 { 16 yaml: `inherit`, 17 want: Secrets{Inherit: true}, 18 }, 19 // struct value 20 { 21 yaml: ` 22 access-token: token 23 `, 24 want: Secrets{ 25 Values: map[string]string{ 26 "access-token": "token", 27 }, 28 }, 29 }, 30 } 31 32 for i, test := range tests { 33 got := new(Secrets) 34 if err := yaml.Unmarshal([]byte(test.yaml), got); err != nil { 35 t.Log(test.yaml) 36 t.Error(err) 37 return 38 } 39 if diff := cmp.Diff(got, &test.want); diff != "" { 40 t.Log(test.yaml) 41 t.Errorf("Unexpected parsing results for test %v", i) 42 t.Log(diff) 43 } 44 } 45 } 46 47 func TestSecrets_Error(t *testing.T) { 48 err := yaml.Unmarshal([]byte("[[]]"), new(Secrets)) 49 if err == nil || err.Error() != "failed to unmarshal secrets" { 50 t.Errorf("Expect error, got %s", err) 51 } 52 }