From 2f777e3658ed7f623c398b8cec23a7c3f81f53f7 Mon Sep 17 00:00:00 2001 From: Kirill Sibirev Date: Tue, 16 Apr 2024 12:24:19 +0200 Subject: [PATCH] Add GetType for components (#237) --- pkg/components/component.go | 2 ++ pkg/components/suite_test.go | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/components/component.go b/pkg/components/component.go index 556ae23f..6c4298ef 100644 --- a/pkg/components/component.go +++ b/pkg/components/component.go @@ -7,6 +7,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy" + "github.com/ytsaurus/yt-k8s-operator/pkg/consts" "github.com/ytsaurus/yt-k8s-operator/pkg/labeller" ) @@ -47,6 +48,7 @@ type Component interface { Sync(ctx context.Context) error Status(ctx context.Context) (ComponentStatus, error) GetName() string + GetType() consts.ComponentType SetReadyCondition(status ComponentStatus) // TODO(nadya73): refactor it diff --git a/pkg/components/suite_test.go b/pkg/components/suite_test.go index ef0dc74f..f11170d9 100644 --- a/pkg/components/suite_test.go +++ b/pkg/components/suite_test.go @@ -13,6 +13,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" + "github.com/ytsaurus/yt-k8s-operator/pkg/consts" mock_yt "github.com/ytsaurus/yt-k8s-operator/pkg/mock" ) @@ -31,12 +32,17 @@ var _ = BeforeSuite(func() { }) type FakeComponent struct { - name string - status ComponentStatus + name string + compType consts.ComponentType + status ComponentStatus } -func NewFakeComponent(name string) *FakeComponent { - return &FakeComponent{name: name, status: SimpleStatus(SyncStatusReady)} +func NewFakeComponent(name string, compType consts.ComponentType) *FakeComponent { + return &FakeComponent{ + name: name, + compType: compType, + status: SimpleStatus(SyncStatusReady), + } } func (fc *FakeComponent) IsUpdatable() bool { @@ -63,6 +69,10 @@ func (fc *FakeComponent) GetName() string { return fc.name } +func (fc *FakeComponent) GetType() consts.ComponentType { + return fc.compType +} + func (fc *FakeComponent) SetReadyCondition(status ComponentStatus) {} type FakeServer struct { @@ -132,7 +142,7 @@ type FakeYtsaurusClient struct { func NewFakeYtsaurusClient(client *mock_yt.MockClient) *FakeYtsaurusClient { return &FakeYtsaurusClient{ - FakeComponent: *NewFakeComponent("ytsaurus_client"), + FakeComponent: *NewFakeComponent("ytsaurus_client", consts.YtsaurusClientType), client: client, } } @@ -145,6 +155,6 @@ func (fyc *FakeYtsaurusClient) SetStatus(status ComponentStatus) { fyc.status = status } -func (fc *FakeYtsaurusClient) IsUpdatable() bool { +func (fyc *FakeYtsaurusClient) IsUpdatable() bool { return false }