File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ package  controller
2+ 
3+ import  (
4+ 	"fmt" 
5+ 	"testing" 
6+ 
7+ 	"k8s.io/apimachinery/pkg/util/validation" 
8+ )
9+ 
10+ func  TestK8sNameHash (t  * testing.T ) {
11+ 	tt  :=  []struct  {
12+ 		input    []string 
13+ 		expHash  string 
14+ 	}{
15+ 		{
16+ 			[]string {"test1" },
17+ 			"wrckybtbh7enmn4vx2nnbpvpkuarsnvm" ,
18+ 		},
19+ 		{
20+ 			// check that the same string produces the same hash 
21+ 			[]string {"test1" },
22+ 			"wrckybtbh7enmn4vx2nnbpvpkuarsnvm" ,
23+ 		},
24+ 		{
25+ 			[]string {"bla" },
26+ 			"76tha37scj5hjglta4tvn6b4kmxeh3ic" ,
27+ 		},
28+ 		{
29+ 			[]string {"some other test" , "this is a very, very long string" },
30+ 			"fkkzqgh27xym6tqbswyql3wy4atsf6pt" ,
31+ 		},
32+ 	}
33+ 
34+ 	for  _ , tc  :=  range  tt  {
35+ 		t .Run (fmt .Sprint (tc .input ), func (t  * testing.T ) {
36+ 			res  :=  K8sNameHash (tc .input ... )
37+ 
38+ 			if  res  !=  tc .expHash  {
39+ 				t .Errorf ("exp hash %q, got %q" , tc .expHash , res )
40+ 			}
41+ 
42+ 			// ensure the result is a valid DNS1123Subdomain 
43+ 			if  errs  :=  validation .IsDNS1123Subdomain (res ); errs  !=  nil  {
44+ 				t .Errorf ("value %q is invalid: %v" , res , errs )
45+ 			}
46+ 
47+ 		})
48+ 	}
49+ 
50+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments