github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/tree/tree_test.go (about) 1 package tree 2 3 import ( 4 "fmt" 5 "testing" 6 7 "gopkg.in/yaml.v3" 8 ) 9 10 func TestCommon_MarshalYAML(t *testing.T) { 11 12 tests := []struct { 13 name string 14 parsedApiVersion bool 15 wantKey string 16 }{{ 17 name: "It should marshal kind and normal version", 18 parsedApiVersion: false, 19 wantKey: "version", 20 }, { 21 name: "It should marshal kind and api version using the version field", 22 parsedApiVersion: true, 23 wantKey: "apiVersion", 24 }} 25 for _, tt := range tests { 26 t.Run(tt.name, func(t *testing.T) { 27 got, err := yaml.Marshal(NewCommon("akind", "aversion", tt.parsedApiVersion)) 28 if err != nil { 29 t.Error(err) 30 return 31 } 32 gotStr := string(got) 33 wantStr := fmt.Sprintf(`kind: akind 34 %s: aversion 35 `, tt.wantKey) 36 37 if gotStr != wantStr { 38 t.Errorf("MarshalYAML() got = %v, want %v", gotStr, wantStr) 39 } 40 }) 41 } 42 }