Skip to content

Commit

Permalink
test(server): some unit test fails on windows (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya authored Apr 14, 2023
1 parent 8d688c5 commit bc89f30
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
/data
/.env
/.env.*
/.idea
8 changes: 8 additions & 0 deletions server/pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@ func TestCache_Get(t *testing.T) {
assert.NoError(t, e)
assert.Same(t, data, res)
assert.Equal(t, 1, called)
time.Sleep(1 * time.Nanosecond)

res, e = cache.Get(ctx) // second
assert.NoError(t, e)
assert.Same(t, data, res)
assert.Equal(t, 2, called)
time.Sleep(1 * time.Nanosecond)

res, e = cache.Get(ctx) // third
assert.Same(t, err, e)
assert.Same(t, data, res)
assert.Equal(t, 3, called)
time.Sleep(1 * time.Nanosecond)

res, e = cache.Get(ctx) // forth
assert.NoError(t, e)
assert.Same(t, data, res)
assert.Equal(t, 4, called)
}

func TestCache_Get2(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions server/pkg/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package file
import (
"io"
"os"
"path/filepath"
"testing"

"github.com/spf13/afero"
Expand Down Expand Up @@ -166,18 +167,18 @@ func TestFilteredIterator(t *testing.T) {

func TestFsIterator(t *testing.T) {
fs := afero.NewMemMapFs()
_ = fs.MkdirAll("a/b", 0755)
_ = fs.MkdirAll(filepath.Join("a", "b"), 0755)
f, _ := fs.Create("b")
_, _ = f.WriteString("hello")
_ = f.Close()
_, _ = fs.Create("a/b/c")
_, _ = fs.Create(filepath.Join("a", "b", "c"))

a, err := NewFsIterator(fs)
assert.NoError(t, err)

n, err := a.Next()
assert.NoError(t, err)
assert.Equal(t, "a/b/c", n.Path)
assert.Equal(t, filepath.Join("a", "b", "c"), n.Path)
nd, err := io.ReadAll(n.Content)
assert.NoError(t, err)
assert.Equal(t, []byte{}, nd)
Expand Down
6 changes: 4 additions & 2 deletions server/pkg/layer/encoding/shp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestEncodeSHP(t *testing.T) {
want shp.Shape
}{
{
name: "polygon",
layer: &merging.SealedLayerItem{
SealedLayerCommon: merging.SealedLayerCommon{
Merged: layer.Merged{
Expand Down Expand Up @@ -141,13 +142,14 @@ func TestEncodeSHP(t *testing.T) {
assert.NoError(t, err)
en := NewSHPEncoder(tmpFile)
assert.NoError(t, en.Encode(tt.layer))
assert.NoError(t, tmpFile.Close())

shape, err := shp.Open(tmpFile.Name())
assert.NoError(t, err)
assert.True(t, shape.Next())

assert.NoError(t, err)
assert.NoError(t, os.Remove(tmpFile.Name()))
assert.NoError(t, shape.Close())
assert.NoError(t, os.Remove(tmpFile.Name()))

_, p := shape.Shape()
assert.Equal(t, tt.want, p)
Expand Down

0 comments on commit bc89f30

Please sign in to comment.