Skip to content
Open
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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/linuxsuren/go-fake-runtime v0.0.5 h1:x1qvuGMfly3L4BTwx6Hq5oUcuf/1u0kSVPzQylHHpwI=
github.com/linuxsuren/go-fake-runtime v0.0.5/go.mod h1:hlE6bZp76N3YPDsKi5YKOf1XmcJy4rvf8EtkTLYRYLw=
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9 h1:w5prP6ROOxInPV38KL+0laf7ZDIHlidBerhrphHqWHU=
github.com/linuxsuren/go-service v0.0.2-0.20251117091849-c58edc8748d9/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/go-service v0.0.2 h1:4pq+LEXs1/V6qBCVW749PZbaXSQb3dyz/VR+xsdf95o=
github.com/linuxsuren/go-service v0.0.2/go.mod h1:QX22v61PxpOfJa4Xug8qzGTbPjclDZFx2j1PlGLknJw=
github.com/linuxsuren/http-downloader v0.0.99 h1:fEu+HkHdYeLM932c7IfmuaDJqWxVU5sIEnS/Aln8h9o=
Expand Down
37 changes: 37 additions & 0 deletions pkg/server/remote_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,17 @@ func TestStoreManager(t *testing.T) {
}
})

t.Run("GetStores without extension config", func(t *testing.T) {
server, clean := getRemoteServerInTempDirWithoutExtensions()
defer clean()

reply, err := server.GetStores(ctx, &SimpleQuery{})
assert.NoError(t, err)
if assert.Equal(t, 1, len(reply.Data)) {
assert.Equal(t, "local", reply.Data[0].Name)
}
})

t.Run("CreateStore", func(t *testing.T) {
server, clean := getRemoteServerInTempDir()
defer clean()
Expand Down Expand Up @@ -979,6 +990,23 @@ func getRemoteServerInTempDir() (server RunnerServer, call func()) {
return
}

func getRemoteServerInTempDirWithoutExtensions() (server RunnerServer, call func()) {
dir, _ := os.MkdirTemp(os.TempDir(), "remote-server-no-extension")
call = func() { os.RemoveAll(dir) }

themePath := filepath.Join(dir, "data", "theme")
os.MkdirAll(themePath, 0755)
os.WriteFile(filepath.Join(themePath, "simple.json"), []byte(simplePostman), 0755)

bindinPath := filepath.Join(dir, "data", "key-binding")
os.MkdirAll(bindinPath, 0755)
os.WriteFile(filepath.Join(bindinPath, "default.json"), binding, 0755)

writer := atest.NewFileWriter(dir)
server = NewRemoteServer(writer, newLocalloaderFromStore(), nil, nil, dir, 1024*1024*4)
return
}

type fakeLocalLoaderFactory struct {
}

Expand Down Expand Up @@ -1073,6 +1101,15 @@ func TestGetStoreKinds(t *testing.T) {
assert.Equal(t, 1, len(reply.Data))
}

func TestGetStoreKindsWithoutExtensionConfig(t *testing.T) {
server, clean := getRemoteServerInTempDirWithoutExtensions()
defer clean()

reply, err := server.GetStoreKinds(context.Background(), &Empty{})
assert.NoError(t, err)
assert.Empty(t, reply.Data)
}

func TestGetThemes(t *testing.T) {
server, clean := getRemoteServerInTempDir()
defer clean()
Expand Down
11 changes: 8 additions & 3 deletions pkg/testing/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,15 @@ func (s *storeFactory) GetStoreKinds() (kinds []StoreKind, err error) {
storeConfig := &StoreConfig{}

var data []byte
if data, err = os.ReadFile(path.Join(s.configDir, "data", "core", "extension.yaml")); err == nil {
if err = yaml.Unmarshal(data, storeConfig); err == nil {
kinds = storeConfig.Extensions
if data, err = os.ReadFile(path.Join(s.configDir, "data", "core", "extension.yaml")); err != nil {
if os.IsNotExist(err) {
err = nil
}
return
}

if err = yaml.Unmarshal(data, storeConfig); err == nil {
kinds = storeConfig.Extensions
}
return
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/testing/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package testing

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -48,6 +49,35 @@ func TestStoreFactory(t *testing.T) {
assert.NoError(t, err)
})

t.Run("GetStoreKinds when extension config missing", func(t *testing.T) {
dir, err := os.MkdirTemp(os.TempDir(), "store-kind-missing")
assert.NoError(t, err)
defer os.RemoveAll(dir)

factory := NewStoreFactory(dir)
kinds, err := factory.GetStoreKinds()
assert.NoError(t, err)
assert.Empty(t, kinds)
})

t.Run("GetStoreKinds when extension config invalid", func(t *testing.T) {
dir, err := os.MkdirTemp(os.TempDir(), "store-kind-invalid")
assert.NoError(t, err)
defer os.RemoveAll(dir)

coreDir := filepath.Join(dir, "data", "core")
err = os.MkdirAll(coreDir, 0755)
assert.NoError(t, err)

err = os.WriteFile(filepath.Join(coreDir, "extension.yaml"), []byte("items: ["), 0644)
assert.NoError(t, err)

factory := NewStoreFactory(dir)
kinds, err := factory.GetStoreKinds()
assert.Error(t, err)
assert.Nil(t, kinds)
})

t.Run("GetStore", func(t *testing.T) {
store, err := factory.GetStore("db")
assert.Nil(t, err)
Expand Down
Loading