Skip to content

Commit

Permalink
resource asyaml test:
Browse files Browse the repository at this point in the history
  • Loading branch information
shanalily committed Jan 25, 2022
1 parent c988fe6 commit 9424955
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions api/resource/resource_test.go
Expand Up @@ -43,18 +43,54 @@ var testDeployment = factory.FromMap(

const deploymentAsString = `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"pooh"}}`

var testConfigMapNumericNs = factory.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "winnie",
"namespace": "01234",
},
})

//nolint:gosec
const configMapNumericNsAsString = `{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie","namespace":"01234"}}`

func TestAsYAML(t *testing.T) {
expected := `apiVersion: apps/v1
expectedDeployment := `apiVersion: apps/v1
kind: Deployment
metadata:
name: pooh
`
yaml, err := testDeployment.AsYAML()
if err != nil {
t.Fatal(err)
expectedConfigMapNumericNs := `apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
namespace: "01234"
`

tests := []struct {
in *Resource
s string
}{
{
in: testDeployment,
s: expectedDeployment,
},
{
in: testConfigMapNumericNs,
s: expectedConfigMapNumericNs,
},
}
if string(yaml) != expected {
t.Fatalf("--- expected\n%s\n--- got\n%s\n", expected, string(yaml))

for _, test := range tests {
yaml, err := test.in.AsYAML()
if err != nil {
t.Fatal(err)
}
if string(yaml) != test.s {
t.Fatalf("--- expected\n%s\n--- got\n%s\n", test.s, string(yaml))
}
}
}

Expand All @@ -71,6 +107,10 @@ func TestResourceString(t *testing.T) {
in: testDeployment,
s: deploymentAsString,
},
{
in: testConfigMapNumericNs,
s: configMapNumericNsAsString,
},
}
for _, test := range tests {
assert.Equal(t, test.in.String(), test.s)
Expand Down

0 comments on commit 9424955

Please sign in to comment.