grafana/pkg/infra/filestorage/filestorage_test.go
Artur Wierzbicki a8b90d9a25
FileStore: add basic file storage API (#46051)
* #45498: fs API alpha

* #45498: remove grafanaDS changes for filestorage.go

* #45498: fix lint

* #45498: fix lint

* #45498: remove db file storage migration

* #45498: linting

* #45498: linting

* #45498: linting

* #45498: fix imports

* #45498: add comment

* remove StorageName abstractions

* FileStore: add dummy implementation (#46071)

* #45498: bring back grafanaDs changes, add dummy filestorage

* #45498: rename grafanaDs to public

* #45498: modify join

* #45498: review fix

* #45498:  unnecessary leading newline (whitespace) IMPORTANT FIX

* #45498: fix belongsToStorage

* #45498: fix removeStoragePrefix so that it works with abs paths

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2022-03-03 10:53:26 +04:00

47 lines
1.0 KiB
Go

package filestorage
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestFilestorage_removeStoragePrefix(t *testing.T) {
var tests = []struct {
name string
path string
expected string
}{
{
name: "should return root if path is empty",
path: "",
expected: Delimiter,
},
{
name: "should remove prefix folder from path with multiple parts",
path: "public/abc/d",
expected: "/abc/d",
},
{
name: "should return root path if path is just the storage name",
path: "public",
expected: Delimiter,
},
{
name: "should return root path if path is the prefix of storage",
path: "public/",
expected: Delimiter,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s%s", "absolute: ", tt.name), func(t *testing.T) {
require.Equal(t, tt.expected, removeStoragePrefix(Delimiter+tt.path))
})
t.Run(fmt.Sprintf("%s%s", "relative: ", tt.name), func(t *testing.T) {
require.Equal(t, tt.expected, removeStoragePrefix(tt.path))
})
}
}