Allow hash suffixing of arbitrary types

This commit is contained in:
Nick
2020-07-19 19:52:54 +01:00
parent 45eed23b26
commit 4fbe565b36
3 changed files with 56 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import (
"testing"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func TestConfigMapHash(t *testing.T) {
@@ -75,6 +76,39 @@ func TestSecretHash(t *testing.T) {
}
}
func TestUnstructuredHash(t *testing.T) {
cases := []struct {
desc string
unstructured *unstructured.Unstructured
hash string
err string
}{
{"minimal", &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "test/v1",
"kind": "TestResource",
"metadata": map[string]string{"name": "my-resource"}},
}, "2tt46d7f79", ""},
{"with spec", &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "test/v1",
"kind": "TestResource",
"metadata": map[string]string{"name": "my-resource"},
"spec": map[string]interface{}{"foo": 1, "bar": "abc"}},
}, "6gc62g4m6k", ""},
}
for _, c := range cases {
h, err := unstructuredHash(c.unstructured)
if SkipRest(t, c.desc, err, c.err) {
continue
}
if c.hash != h {
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
}
}
}
func TestEncodeConfigMap(t *testing.T) {
cases := []struct {
desc string