package imagerequest import "testing" // TestSourceKey_DiffersForEachSource checks that each source gets a key of // 64 hex characters, the same each time, and that no two of these sources // share one, also when they differ only by a ":" or "%" in the path or query. func TestSourceKey_DiffersForEachSource(t *testing.T) { t.Parallel() sources := []Source{ {Host: testHostCDN, Path: testPathCat}, {Host: testHostCDN, Path: testPathCat, Query: "v=2"}, {Host: "other.example.com", Path: testPathCat}, {Host: testHostCDN, Path: "/c:d"}, {Host: testHostCDN, Path: "/c", Query: "d:"}, {Host: testHostCDN, Path: "/c%3Ad"}, } seen := make(map[SourceKey]Source) for _, source := range sources { key := source.Key() t.Logf("Key() of %+v = %s", source, key) if len(key) != 64 { t.Errorf("Key() of %+v length = %d, want 64", source, len(key)) } if again := source.Key(); again != key { t.Errorf("Key() of %+v not deterministic: %s vs %s", source, key, again) } if earlier, found := seen[key]; found { t.Errorf("Key() gave %+v and %+v the same key", earlier, source) } seen[key] = source } }