Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pmtiles/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ func NormalizeBucketKey(bucket string, prefix string, key string) (string, strin
if strings.HasSuffix(dir, "/") {
dir = dir[:len(dir)-1]
}
return u.Scheme + "://" + u.Host + dir, file, nil
keyWithQuery := file
if u.RawQuery != "" {
keyWithQuery = keyWithQuery + "?" + u.RawQuery
}
return u.Scheme + "://" + u.Host + dir, keyWithQuery, nil
}
fileprotocol := "file://"
if string(os.PathSeparator) != "/" {
Expand Down
28 changes: 28 additions & 0 deletions pmtiles/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func TestNormalizeHttp(t *testing.T) {
assert.Equal(t, "http://example.com/foo", bucket)
}

func TestNormalizeHttpWithQuery(t *testing.T) {
url := "http://example.com/foo/bar.pmtiles?X-Goog-Algorithm=GOOG4&X-Goog-Signature=abc123"
bucket, key, _ := NormalizeBucketKey("", "", url)
assert.Equal(t, "http://example.com/foo", bucket)
assert.Equal(t, "bar.pmtiles?X-Goog-Algorithm=GOOG4&X-Goog-Signature=abc123", key)
}

func TestNormalizePathPrefixServer(t *testing.T) {
bucket, key, _ := NormalizeBucketKey("", "../foo", "")
assert.Equal(t, "", key)
Expand Down Expand Up @@ -84,6 +91,27 @@ func TestHttpBucketRequestNormal(t *testing.T) {
assert.Nil(t, err)
}

func TestHttpBucketRequestWithQuery(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egorbn This test does not fail when the original code is left as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the test are passing both in on github and when running go test ./pmtiles.
image

Am I missing something?

The publish step is failing because it's complaining about a password:
image

What do I need to do to fix that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The publish step is failing because it's complaining about a password

Don't worry about this, it only matters when running on main

All the test are passing both in on github and when running

The test does not fail before the code change, so are you sure this is an effective test?

mock := ClientMock{}
header := http.Header{}
header.Add("ETag", "etag")
bucket := HTTPBucket{"http://tiles.example.com/tiles", &mock}
mock.response = &http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader("abc")),
Header: header,
}
data, etag, status, err := bucket.NewRangeReaderEtag(context.Background(), "a/b/c?token=xyz", 50, 3, "")
assert.Equal(t, "http://tiles.example.com/tiles/a/b/c?token=xyz", mock.request.URL.String())
assert.Equal(t, 200, status)
assert.Nil(t, err)
b, err := io.ReadAll(data)
assert.Nil(t, err)
assert.Equal(t, "abc", string(b))
assert.Equal(t, "etag", etag)
assert.Nil(t, err)
}

func TestHttpBucketRequestRequestEtag(t *testing.T) {
mock := ClientMock{}
header := http.Header{}
Expand Down
Loading