mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 16:57:14 -06:00
36f42853dd
* Read desired mode from config * Update playlist integration tests * Add mode 1 playlist integration tests * Add mode 0 dual writing to playlist integration tests * Add documentation for the different dual writing modes
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package rest
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
|
|
"github.com/grafana/grafana/pkg/infra/kvstore"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
)
|
|
|
|
func TestSetDualWritingMode(t *testing.T) {
|
|
type testCase struct {
|
|
name string
|
|
stackID string
|
|
desiredMode DualWriterMode
|
|
expectedMode DualWriterMode
|
|
}
|
|
tests :=
|
|
// #TODO add test cases for kv store failures. Requires adding support in kvstore test_utils.go
|
|
[]testCase{
|
|
{
|
|
name: "should return a mode 2 dual writer when mode 2 is set as the desired mode",
|
|
stackID: "stack-1",
|
|
desiredMode: Mode2,
|
|
expectedMode: Mode2,
|
|
},
|
|
{
|
|
name: "should return a mode 1 dual writer when mode 1 is set as the desired mode",
|
|
stackID: "stack-1",
|
|
desiredMode: Mode1,
|
|
expectedMode: Mode1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
l := (LegacyStorage)(nil)
|
|
s := (Storage)(nil)
|
|
m := &mock.Mock{}
|
|
|
|
ls := legacyStoreMock{m, l}
|
|
us := storageMock{m, s}
|
|
|
|
kvStore := kvstore.WithNamespace(kvstore.NewFakeKVStore(), 0, "storage.dualwriting."+tt.stackID)
|
|
|
|
dw, err := SetDualWritingMode(context.Background(), kvStore, ls, us, playlist.GROUPRESOURCE, tt.desiredMode)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tt.expectedMode, dw.Mode())
|
|
|
|
// check kv store
|
|
val, ok, err := kvStore.Get(context.Background(), playlist.GROUPRESOURCE)
|
|
assert.True(t, ok)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, val, fmt.Sprint(tt.expectedMode))
|
|
}
|
|
}
|