2024-04-11 13:41:05 +02:00
|
|
|
package rest
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2024-04-12 14:21:10 +02:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2024-04-11 13:41:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMode3(t *testing.T) {
|
|
|
|
|
var ls = (LegacyStorage)(nil)
|
|
|
|
|
var s = (Storage)(nil)
|
|
|
|
|
lsSpy := NewLegacyStorageSpyClient(ls)
|
|
|
|
|
sSpy := NewStorageSpyClient(s)
|
|
|
|
|
|
|
|
|
|
dw := NewDualWriterMode3(lsSpy, sSpy)
|
|
|
|
|
|
2024-04-12 14:21:10 +02:00
|
|
|
// Create: it should use the Legacy Create implementation
|
|
|
|
|
_, err := dw.Create(context.Background(), &dummyObject{}, func(context.Context, runtime.Object) error { return nil }, &metav1.CreateOptions{})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, lsSpy.Counts("LegacyStorage.Create"))
|
|
|
|
|
assert.Equal(t, 1, sSpy.Counts("Storage.Create"))
|
|
|
|
|
|
2024-04-11 13:41:05 +02:00
|
|
|
// Get: it should use the Storage Get implementation
|
2024-04-12 14:21:10 +02:00
|
|
|
_, err = dw.Get(context.Background(), kind, &metav1.GetOptions{})
|
2024-04-11 13:41:05 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, lsSpy.Counts("LegacyStorage.Get"))
|
|
|
|
|
assert.Equal(t, 1, sSpy.Counts("Storage.Get"))
|
|
|
|
|
|
|
|
|
|
// List: it should use the Storage List implementation
|
|
|
|
|
_, err = dw.List(context.Background(), &metainternalversion.ListOptions{})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, lsSpy.Counts("LegacyStorage.List"))
|
|
|
|
|
assert.Equal(t, 1, sSpy.Counts("Storage.List"))
|
2024-04-15 09:48:31 +01:00
|
|
|
|
|
|
|
|
// Delete: it should use call both Legacy and Storage Delete methods
|
|
|
|
|
var deleteValidation = func(ctx context.Context, obj runtime.Object) error { return nil }
|
|
|
|
|
_, _, err = dw.Delete(context.Background(), kind, deleteValidation, &metav1.DeleteOptions{})
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, lsSpy.Counts("LegacyStorage.Delete"))
|
|
|
|
|
assert.Equal(t, 1, sSpy.Counts("Storage.Delete"))
|
2024-04-11 13:41:05 +02:00
|
|
|
}
|