Skip to content

Commit 48230a7

Browse files
authored
Merge pull request #204 from chrigl/test-object-decode-encode
Added parsing to objmetadata_test.TestCreateObjMetadata
2 parents 7d23762 + 3757e60 commit 48230a7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/object/objmetadata_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package object
55

66
import (
7+
"strings"
78
"testing"
89

910
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -97,7 +98,22 @@ func TestCreateObjMetadata(t *testing.T) {
9798
if err != nil {
9899
t.Errorf("Error creating ObjMetadata when it should have worked.")
99100
} else if test.expected != inv.String() {
100-
t.Errorf("Expected inventory (%s) != created inventory(%s)\n", test.expected, inv.String())
101+
t.Errorf("Expected inventory\n(%s) != created inventory\n(%s)\n", test.expected, inv.String())
102+
}
103+
104+
// Parsing back the just created inventory string to ObjMetadata,
105+
// so that tests will catch any change to CreateObjMetadata that
106+
// would break ParseObjMetadata.
107+
expectedObjMetadata := &ObjMetadata{
108+
Namespace: strings.TrimSpace(test.namespace),
109+
Name: strings.TrimSpace(test.name),
110+
GroupKind: test.gk,
111+
}
112+
actual, err := ParseObjMetadata(inv.String())
113+
if err != nil {
114+
t.Errorf("Error parsing back ObjMetadata, when it should have worked.")
115+
} else if !expectedObjMetadata.Equals(actual) {
116+
t.Errorf("Expected inventory (%s) != parsed inventory (%s)\n", expectedObjMetadata, actual)
101117
}
102118
}
103119
if test.isError && err == nil {

0 commit comments

Comments
 (0)