@@ -2,6 +2,7 @@ package controller
22
33import (
44 "crypto/sha3"
5+ "strings"
56 "testing"
67
78 "github.com/google/uuid"
@@ -132,3 +133,59 @@ func Test_K8sObjectUUID(t *testing.T) {
132133 })
133134 }
134135}
136+
137+ func Test_NameHashSHAKE128Base32 (t * testing.T ) {
138+ testCases := []struct {
139+ input []string
140+ expected string
141+ }{
142+ {
143+ input : []string {"example" },
144+ expected : "epgccknc" ,
145+ },
146+ {
147+ input : []string {corev1 .NamespaceDefault , "example" },
148+ expected : "fphxsdub" ,
149+ },
150+ }
151+ for _ , tC := range testCases {
152+ t .Run (strings .Join (tC .input , " " ), func (t * testing.T ) {
153+ actual := NameHashSHAKE128Base32 (tC .input ... )
154+ assert .Equal (t , tC .expected , actual )
155+ })
156+ }
157+ }
158+
159+ func Test_ObjectHashSHAKE128Base32 (t * testing.T ) {
160+ testCases := []struct {
161+ desc string
162+ obj client.Object
163+ expected string
164+ }{
165+ {
166+ desc : "should work with config map" ,
167+ obj : & corev1.ConfigMap {
168+ ObjectMeta : metav1.ObjectMeta {
169+ Name : "example" ,
170+ Namespace : "default" ,
171+ },
172+ },
173+ expected : "fphxsdub" , // same as in Test_K8sNameUUID
174+ },
175+ {
176+ desc : "should work with config map and empty namespace" ,
177+ obj : & corev1.ConfigMap {
178+ ObjectMeta : metav1.ObjectMeta {
179+ Name : "example" ,
180+ },
181+ },
182+ expected : "fphxsdub" , // same as above
183+ },
184+ }
185+ for _ , tC := range testCases {
186+ t .Run (tC .desc , func (t * testing.T ) {
187+ actual := ObjectHashSHAKE128Base32 (tC .obj )
188+ assert .Equal (t , tC .expected , actual )
189+ })
190+ }
191+ }
0 commit comments