Skip to content

Commit

Permalink
add CI for checking formatting (#83)
Browse files Browse the repository at this point in the history
* add CI for checking formatting

* go fmt [#47]
  • Loading branch information
bdon authored Sep 22, 2023
1 parent 72a7c2a commit ad2801a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 83 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ jobs:
with:
go-version: '^1.18.0'
- run: go test ./pmtiles
- run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
7 changes: 3 additions & 4 deletions pmtiles/bucket_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package pmtiles

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"strings"
"fmt"
"testing"
)


func TestNormalizeLocalFile(t *testing.T) {
bucket, key, _ := NormalizeBucketKey("", "", "../foo/bar.pmtiles")
assert.Equal(t, "bar.pmtiles", key)
Expand All @@ -32,4 +31,4 @@ func TestNormalizePathPrefixServer(t *testing.T) {
fmt.Println(bucket)
assert.True(t, strings.HasSuffix(bucket, "/foo"))
assert.True(t, strings.HasPrefix(bucket, "file://"))
}
}
68 changes: 34 additions & 34 deletions pmtiles/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ import (
func TestResolver(t *testing.T) {
resolver := NewResolver(true, true)
resolver.AddTileIsNew(1, []byte{0x1, 0x2})
assert.Equal(t,1,len(resolver.Entries))
assert.Equal(t, 1, len(resolver.Entries))
resolver.AddTileIsNew(2, []byte{0x1, 0x3})
assert.Equal(t,uint64(52),resolver.Offset)
assert.Equal(t, uint64(52), resolver.Offset)
is_new, _ := resolver.AddTileIsNew(3, []byte{0x1, 0x2})
assert.False(t,is_new)
assert.Equal(t,uint64(52),resolver.Offset)
assert.False(t, is_new)
assert.Equal(t, uint64(52), resolver.Offset)
resolver.AddTileIsNew(4, []byte{0x1, 0x2})
assert.Equal(t,3,len(resolver.Entries))
assert.Equal(t, 3, len(resolver.Entries))
resolver.AddTileIsNew(6, []byte{0x1, 0x2})
assert.Equal(t,4,len(resolver.Entries))
assert.Equal(t, 4, len(resolver.Entries))
}

func TestV2UpgradeBarebones(t *testing.T) {
header, json_metadata, err := v2_to_header_json(map[string]interface{}{
"bounds": "-180.0,-85,178,83",
"attribution": "abcd",
}, []byte{0x1f, 0x8b, 0x0, 0x0})
assert.Nil(t,err)
assert.Nil(t, err)
_, ok := json_metadata["attribution"]
assert.True(t,ok)
assert.Equal(t,int32(-180*10000000), header.MinLonE7)
assert.Equal(t,int32(-85*10000000), header.MinLatE7)
assert.Equal(t,int32(178*10000000), header.MaxLonE7)
assert.Equal(t,int32(83*10000000), header.MaxLatE7)
assert.True(t, ok)
assert.Equal(t, int32(-180*10000000), header.MinLonE7)
assert.Equal(t, int32(-85*10000000), header.MinLatE7)
assert.Equal(t, int32(178*10000000), header.MaxLonE7)
assert.Equal(t, int32(83*10000000), header.MaxLatE7)
_, ok = json_metadata["bounds"]
assert.False(t,ok)
assert.Equal(t,Gzip,int(header.TileCompression))
assert.Equal(t,Mvt,int(header.TileType))
assert.False(t, ok)
assert.Equal(t, Gzip, int(header.TileCompression))
assert.Equal(t, Mvt, int(header.TileType))
}

func TestV2UpgradeExtra(t *testing.T) {
Expand All @@ -47,7 +47,7 @@ func TestV2UpgradeExtra(t *testing.T) {
"compression": "gzip",
"json": "{\"abc\":\"def\"}",
}, []byte{0x0, 0x0, 0x0, 0x0})
assert.Nil(t,err)
assert.Nil(t, err)
assert.Equal(t, int32(-122.1906*10000000), header.CenterLonE7)
assert.Equal(t, int32(37.7599*10000000), header.CenterLatE7)
assert.Equal(t, uint8(11), header.CenterZoom)
Expand Down Expand Up @@ -94,8 +94,8 @@ func TestV2UpgradeInfer(t *testing.T) {
"bounds": "-180.0,-85,180,85",
}, []byte{0xff, 0xd8, 0xff, 0xe0})
assert.Nil(t, err)
assert.Equal(t,Jpeg, int(header.TileType))
assert.Equal(t,NoCompression, int(header.TileCompression))
assert.Equal(t, Jpeg, int(header.TileType))
assert.Equal(t, NoCompression, int(header.TileCompression))
header, _, err = v2_to_header_json(map[string]interface{}{
"bounds": "-180.0,-85,180,85",
}, []byte{0x89, 0x50, 0x4e, 0x47})
Expand All @@ -110,7 +110,7 @@ func TestV2UpgradeInfer(t *testing.T) {
header, _, err = v2_to_header_json(map[string]interface{}{
"bounds": "-180.0,-85,180,85",
}, []byte{0x1f, 0x8b, 00, 00})
assert.Nil(t,err)
assert.Nil(t, err)
assert.Equal(t, Mvt, int(header.TileType))
assert.Equal(t, Gzip, int(header.TileCompression))
}
Expand All @@ -128,14 +128,14 @@ func TestMbtiles(t *testing.T) {
"json", "{\"vector_layers\":[{\"abc\":123}],\"tilestats\":{\"def\":456}}",
"compression", "gzip",
})
assert.Nil(t,err)
assert.Equal(t,int32(-180*10000000), header.MinLonE7)
assert.Equal(t,int32(-85*10000000), header.MinLatE7)
assert.Equal(t,int32(180*10000000), header.MaxLonE7)
assert.Equal(t,int32(85*10000000), header.MaxLatE7)
assert.Nil(t, err)
assert.Equal(t, int32(-180*10000000), header.MinLonE7)
assert.Equal(t, int32(-85*10000000), header.MinLatE7)
assert.Equal(t, int32(180*10000000), header.MaxLonE7)
assert.Equal(t, int32(85*10000000), header.MaxLatE7)
assert.Equal(t, Mvt, int(header.TileType))
assert.Equal(t,int32(-122.1906*10000000), header.CenterLonE7)
assert.Equal(t,int32(37.7599*10000000), header.CenterLatE7)
assert.Equal(t, int32(-122.1906*10000000), header.CenterLonE7)
assert.Equal(t, int32(37.7599*10000000), header.CenterLatE7)
assert.Equal(t, 11, int(header.CenterZoom))
assert.Equal(t, Gzip, int(header.TileCompression))

Expand Down Expand Up @@ -187,13 +187,13 @@ func TestMbtilesMissingBoundsCenter(t *testing.T) {
"json", "{\"vector_layers\":[{\"abc\":123}],\"tilestats\":{\"def\":456}}",
"compression", "gzip",
})
assert.Nil(t,err)
assert.Equal(t,int32(-180*10000000), header.MinLonE7)
assert.Equal(t,int32(-85*10000000), header.MinLatE7)
assert.Equal(t,int32(180*10000000), header.MaxLonE7)
assert.Equal(t,int32(85*10000000), header.MaxLatE7)
assert.Equal(t,int32(0), header.CenterLonE7)
assert.Equal(t,int32(0), header.CenterLatE7)
assert.Nil(t, err)
assert.Equal(t, int32(-180*10000000), header.MinLonE7)
assert.Equal(t, int32(-85*10000000), header.MinLatE7)
assert.Equal(t, int32(180*10000000), header.MaxLonE7)
assert.Equal(t, int32(85*10000000), header.MaxLatE7)
assert.Equal(t, int32(0), header.CenterLonE7)
assert.Equal(t, int32(0), header.CenterLatE7)
}

func TestMbtilesDegenerateBounds(t *testing.T) {
Expand All @@ -208,5 +208,5 @@ func TestMbtilesDegenerateBounds(t *testing.T) {
"json", "{\"vector_layers\":[{\"abc\":123}],\"tilestats\":{\"def\":456}}",
"compression", "gzip",
})
assert.NotNil(t,err)
assert.NotNil(t, err)
}
52 changes: 26 additions & 26 deletions pmtiles/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ func TestHeaderRoundtrip(t *testing.T) {
header.CenterLatE7 = 3.2 * 10000000
b := serialize_header(header)
result, _ := deserialize_header(b)
assert.Equal(t,uint64(1),result.RootOffset)
assert.Equal(t,uint64(2),result.RootLength)
assert.Equal(t,uint64(3),result.MetadataOffset)
assert.Equal(t,uint64(4),result.MetadataLength)
assert.Equal(t,uint64(5),result.LeafDirectoryOffset)
assert.Equal(t,uint64(6),result.LeafDirectoryLength)
assert.Equal(t,uint64(7),result.TileDataOffset)
assert.Equal(t,uint64(8),result.TileDataLength)
assert.Equal(t,uint64(9),result.AddressedTilesCount)
assert.Equal(t,uint64(10),result.TileEntriesCount)
assert.Equal(t,uint64(11),result.TileContentsCount)
assert.Equal(t,true,result.Clustered)
assert.Equal(t,Gzip,int(result.InternalCompression))
assert.Equal(t,Brotli,int(result.TileCompression))
assert.Equal(t,Mvt,int(result.TileType))
assert.Equal(t,uint8(1),result.MinZoom)
assert.Equal(t,uint8(2),result.MaxZoom)
assert.Equal(t,int32(11000000), result.MinLonE7)
assert.Equal(t,int32(21000000), result.MinLatE7)
assert.Equal(t,int32(12000000), result.MaxLonE7)
assert.Equal(t,int32(22000000), result.MaxLatE7)
assert.Equal(t,uint8(3),result.CenterZoom)
assert.Equal(t,int32(31000000), result.CenterLonE7)
assert.Equal(t,int32(32000000), result.CenterLatE7)
assert.Equal(t, uint64(1), result.RootOffset)
assert.Equal(t, uint64(2), result.RootLength)
assert.Equal(t, uint64(3), result.MetadataOffset)
assert.Equal(t, uint64(4), result.MetadataLength)
assert.Equal(t, uint64(5), result.LeafDirectoryOffset)
assert.Equal(t, uint64(6), result.LeafDirectoryLength)
assert.Equal(t, uint64(7), result.TileDataOffset)
assert.Equal(t, uint64(8), result.TileDataLength)
assert.Equal(t, uint64(9), result.AddressedTilesCount)
assert.Equal(t, uint64(10), result.TileEntriesCount)
assert.Equal(t, uint64(11), result.TileContentsCount)
assert.Equal(t, true, result.Clustered)
assert.Equal(t, Gzip, int(result.InternalCompression))
assert.Equal(t, Brotli, int(result.TileCompression))
assert.Equal(t, Mvt, int(result.TileType))
assert.Equal(t, uint8(1), result.MinZoom)
assert.Equal(t, uint8(2), result.MaxZoom)
assert.Equal(t, int32(11000000), result.MinLonE7)
assert.Equal(t, int32(21000000), result.MinLatE7)
assert.Equal(t, int32(12000000), result.MaxLonE7)
assert.Equal(t, int32(22000000), result.MaxLatE7)
assert.Equal(t, uint8(3), result.CenterZoom)
assert.Equal(t, int32(31000000), result.CenterLonE7)
assert.Equal(t, int32(32000000), result.CenterLatE7)
}

func TestOptimizeDirectories(t *testing.T) {
Expand Down Expand Up @@ -168,6 +168,6 @@ func TestBuildRootsLeaves(t *testing.T) {
entries := []EntryV3{
{TileId: 100, Offset: 1, Length: 1, RunLength: 0},
}
_, _, num_leaves := build_roots_leaves(entries,1)
_, _, num_leaves := build_roots_leaves(entries, 1)
assert.Equal(t, 1, num_leaves)
}
}
4 changes: 2 additions & 2 deletions pmtiles/readerv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func TestUint24(t *testing.T) {
b := []byte{255, 255, 255}
assert.Equal(t,uint32(16777215), readUint24(b))
assert.Equal(t, uint32(16777215), readUint24(b))
b = []byte{255, 0, 0}
assert.Equal(t, uint32(255), readUint24(b))
}
Expand All @@ -21,5 +21,5 @@ func TestUint48(t *testing.T) {

func TestGetParentTile(t *testing.T) {
a := Zxy{Z: 8, X: 125, Y: 69}
assert.Equal(t,Zxy{Z: 7, X: 62, Y: 34},GetParentTile(a,7) )
assert.Equal(t, Zxy{Z: 7, X: 62, Y: 34}, GetParentTile(a, 7))
}
34 changes: 17 additions & 17 deletions pmtiles/tile_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ func TestExtremes(t *testing.T) {
}

func TestParent(t *testing.T) {
assert.Equal(t, ZxyToId(0,0,0), ParentId(ZxyToId(1,0,0)))
assert.Equal(t, ZxyToId(0, 0, 0), ParentId(ZxyToId(1, 0, 0)))

assert.Equal(t, ZxyToId(1,0,0), ParentId(ZxyToId(2,0,0)))
assert.Equal(t, ZxyToId(1,0,0), ParentId(ZxyToId(2,0,1)))
assert.Equal(t, ZxyToId(1,0,0), ParentId(ZxyToId(2,1,0)))
assert.Equal(t, ZxyToId(1,0,0), ParentId(ZxyToId(2,1,1)))
assert.Equal(t, ZxyToId(1, 0, 0), ParentId(ZxyToId(2, 0, 0)))
assert.Equal(t, ZxyToId(1, 0, 0), ParentId(ZxyToId(2, 0, 1)))
assert.Equal(t, ZxyToId(1, 0, 0), ParentId(ZxyToId(2, 1, 0)))
assert.Equal(t, ZxyToId(1, 0, 0), ParentId(ZxyToId(2, 1, 1)))

assert.Equal(t, ZxyToId(1,0,1), ParentId(ZxyToId(2,0,2)))
assert.Equal(t, ZxyToId(1,0,1), ParentId(ZxyToId(2,0,3)))
assert.Equal(t, ZxyToId(1,0,1), ParentId(ZxyToId(2,1,2)))
assert.Equal(t, ZxyToId(1,0,1), ParentId(ZxyToId(2,1,3)))
assert.Equal(t, ZxyToId(1, 0, 1), ParentId(ZxyToId(2, 0, 2)))
assert.Equal(t, ZxyToId(1, 0, 1), ParentId(ZxyToId(2, 0, 3)))
assert.Equal(t, ZxyToId(1, 0, 1), ParentId(ZxyToId(2, 1, 2)))
assert.Equal(t, ZxyToId(1, 0, 1), ParentId(ZxyToId(2, 1, 3)))

assert.Equal(t, ZxyToId(1,1,0), ParentId(ZxyToId(2,2,0)))
assert.Equal(t, ZxyToId(1,1,0), ParentId(ZxyToId(2,2,1)))
assert.Equal(t, ZxyToId(1,1,0), ParentId(ZxyToId(2,3,0)))
assert.Equal(t, ZxyToId(1,1,0), ParentId(ZxyToId(2,3,1)))
assert.Equal(t, ZxyToId(1, 1, 0), ParentId(ZxyToId(2, 2, 0)))
assert.Equal(t, ZxyToId(1, 1, 0), ParentId(ZxyToId(2, 2, 1)))
assert.Equal(t, ZxyToId(1, 1, 0), ParentId(ZxyToId(2, 3, 0)))
assert.Equal(t, ZxyToId(1, 1, 0), ParentId(ZxyToId(2, 3, 1)))

assert.Equal(t, ZxyToId(1,1,1), ParentId(ZxyToId(2,2,2)))
assert.Equal(t, ZxyToId(1,1,1), ParentId(ZxyToId(2,2,3)))
assert.Equal(t, ZxyToId(1,1,1), ParentId(ZxyToId(2,3,2)))
assert.Equal(t, ZxyToId(1,1,1), ParentId(ZxyToId(2,3,3)))
assert.Equal(t, ZxyToId(1, 1, 1), ParentId(ZxyToId(2, 2, 2)))
assert.Equal(t, ZxyToId(1, 1, 1), ParentId(ZxyToId(2, 2, 3)))
assert.Equal(t, ZxyToId(1, 1, 1), ParentId(ZxyToId(2, 3, 2)))
assert.Equal(t, ZxyToId(1, 1, 1), ParentId(ZxyToId(2, 3, 3)))
}

0 comments on commit ad2801a

Please sign in to comment.