@@ -37,6 +37,9 @@ func TestParseEndpoint(t *testing.T) {
3737 {"ftp://example.com" , true , "" },
3838 {"http://example.com" , false , "http://example.com" },
3939 {"https://example.com" , false , "https://example.com" },
40+ {"http://EXAMPLE.COM" , false , "http://example.com" },
41+ {"https://EXAMPLE.COM:8080/Path" , false , "https://example.com:8080/Path" },
42+ {" MIXED.case.com/path/ " , false , "http://mixed.case.com/path" },
4043 {"http://example!@#!?//#" , true , "" },
4144 }
4245
@@ -51,6 +54,31 @@ func TestParseEndpoint(t *testing.T) {
5154 }
5255}
5356
57+ func TestEqualURL (t * testing.T ) {
58+ cases := []struct {
59+ url1 string
60+ url2 string
61+ expected bool
62+ }{
63+ {"http://example.com:8080/v2" , "http://example.com:8080/v2" , true },
64+ {"http://EXAMPLE.COM:8080/v2" , "http://example.com:8080/v2" , true },
65+ {"http://example.com:8080/V2" , "http://example.com:8080/v2" , false },
66+ {"https://core:8080" , "https://CORE:8080" , true },
67+ {"http://example.com" , "https://example.com" , false },
68+ {"http://example.com:8080" , "http://example.com:8081" , false },
69+ {"http://example.com/foo" , "http://example.com/bar" , false },
70+ {"://invalid-url-1" , "http://example.com" , false },
71+ {"http://example.com" , "://invalid-url-2" , false },
72+ {"http://example.com/A%" , "http://example.com/a%" , false },
73+ }
74+
75+ for _ , c := range cases {
76+ t .Run (c .url1 + "_vs_" + c .url2 , func (t * testing.T ) {
77+ assert .Equal (t , c .expected , EqualURL (c .url1 , c .url2 ))
78+ })
79+ }
80+ }
81+
5482func TestParseRepository (t * testing.T ) {
5583 repository := "library/ubuntu"
5684 project , rest := ParseRepository (repository )
@@ -155,13 +183,28 @@ func TestGenerateRandomString(t *testing.T) {
155183 }
156184}
157185
186+ func TestGenerateRandomStringOrError (t * testing.T ) {
187+ str , err := GenerateRandomStringOrError ()
188+ assert .Nil (t , err )
189+ assert .Equal (t , 32 , len (str ))
190+ str2 , err := GenerateRandomStringOrError ()
191+ assert .Nil (t , err )
192+ assert .NotEqual (t , str , str2 )
193+ }
194+
158195func TestGenerateRandomStringWithLen (t * testing.T ) {
159196 str := GenerateRandomStringWithLen (16 )
160197 if len (str ) != 16 {
161198 t .Errorf ("Failed to generate ramdom string with fixed length." )
162199 }
163200}
164201
202+ func TestGenerateRandomStringWithLenAndError (t * testing.T ) {
203+ str , err := GenerateRandomStringWithLenAndError (16 )
204+ assert .Nil (t , err )
205+ assert .Equal (t , 16 , len (str ))
206+ }
207+
165208func TestTestTCPConn (t * testing.T ) {
166209 server := httptest .NewServer (nil )
167210 defer server .Close ()
0 commit comments