diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-03-29 20:36:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 20:36:07 +0000 |
commit | f24fabba13df6d442b120cb88fa57287ab85e2de (patch) | |
tree | 109299ef9cd051e08380119b41288f970443ed2a /pkg/domain/infra/abi/play_test.go | |
parent | c8af1747320bb9506ab4ea80892f0dae81c03a95 (diff) | |
parent | 1386f90467e9111533742b40f91018f908efea81 (diff) | |
download | podman-f24fabba13df6d442b120cb88fa57287ab85e2de.tar.gz podman-f24fabba13df6d442b120cb88fa57287ab85e2de.tar.bz2 podman-f24fabba13df6d442b120cb88fa57287ab85e2de.zip |
Merge pull request #9868 from mheon/310_backports
Final backports for v3.1.0
Diffstat (limited to 'pkg/domain/infra/abi/play_test.go')
-rw-r--r-- | pkg/domain/infra/abi/play_test.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/pkg/domain/infra/abi/play_test.go b/pkg/domain/infra/abi/play_test.go index 4354a3835..bbc7c3493 100644 --- a/pkg/domain/infra/abi/play_test.go +++ b/pkg/domain/infra/abi/play_test.go @@ -89,3 +89,100 @@ data: }) } } + +func TestGetKubeKind(t *testing.T) { + tests := []struct { + name string + kubeYAML string + expectError bool + expectedErrorMsg string + expected string + }{ + { + "ValidKubeYAML", + ` +apiVersion: v1 +kind: Pod +`, + false, + "", + "Pod", + }, + { + "InvalidKubeYAML", + "InvalidKubeYAML", + true, + "cannot unmarshal", + "", + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + kind, err := getKubeKind([]byte(test.kubeYAML)) + if test.expectError { + assert.Error(t, err) + assert.Contains(t, err.Error(), test.expectedErrorMsg) + } else { + assert.NoError(t, err) + assert.Equal(t, test.expected, kind) + } + }) + } +} + +func TestSplitMultiDocYAML(t *testing.T) { + tests := []struct { + name string + kubeYAML string + expectError bool + expectedErrorMsg string + expected int + }{ + { + "ValidNumberOfDocs", + ` +apiVersion: v1 +kind: Pod +--- +apiVersion: v1 +kind: Pod +--- +apiVersion: v1 +kind: Pod +`, + false, + "", + 3, + }, + { + "InvalidMultiDocYAML", + ` +apiVersion: v1 +kind: Pod +--- +apiVersion: v1 +kind: Pod +- +`, + true, + "multi doc yaml could not be split", + 0, + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + docs, err := splitMultiDocYAML([]byte(test.kubeYAML)) + if test.expectError { + assert.Error(t, err) + assert.Contains(t, err.Error(), test.expectedErrorMsg) + } else { + assert.NoError(t, err) + assert.Equal(t, test.expected, len(docs)) + } + }) + } +} |