Skip to content

Commit 531f052

Browse files
authored
Merge pull request #168 from EmmEff/update-unit-tests
Merge unit test from v1.3
2 parents c112abf + c18657e commit 531f052

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

client/pull_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,38 @@ func writeBlob(t *testing.T, sampleBytes []byte, start, end int64, code int, w h
150150
}
151151
}
152152

153+
func TestSameHost(t *testing.T) {
154+
tests := []struct {
155+
name string
156+
host1 string
157+
host2 string
158+
same bool
159+
}{
160+
{"Simple", "http://testhost", "http://testhost", true},
161+
{"SimpleHTTPS", "https://testhost", "https://testhost", true},
162+
{"SimpleWithPort", "http://testhost:1234", "http://testhost:1234", true},
163+
{"MismatchedScheme", "https://anotherhost", "http://anotherhost", false},
164+
{"DifferentHostNames", "https://testhost1", "https://testhost2", false},
165+
{"DifferentHostNamesAndScheme", "http://testhost1", "https://testhost2", false},
166+
{"WithCreds", "http://user:password@testhost1", "http://testhost1", true},
167+
{"FullyQualified", "http://testhost.testdomain", "http://testhost.testdomain", true},
168+
{"QualifiedVsNot", "http://testhost", "http://testhost.testdomain", false},
169+
{"UpperAndLowercase", "http://TESTHOST", "http://testhost", true},
170+
}
171+
172+
for _, tt := range tests {
173+
t.Run(tt.name, func(t *testing.T) {
174+
host1, _ := url.Parse(tt.host1)
175+
host2, _ := url.Parse(tt.host2)
176+
177+
result := samehost(host1, host2)
178+
if got, want := result, tt.same; got != want {
179+
t.Fatalf("Unexpected results: host1 %v, host2 %v: got %v, want %v)", host1.String(), host2.String(), got, want)
180+
}
181+
})
182+
}
183+
}
184+
153185
// TestLegacyDownloadImage downloads random image data from mock library and compares hash to
154186
// ensure download integrity.
155187
func TestLegacyDownloadImage(t *testing.T) {

0 commit comments

Comments
 (0)