From 8883ca6328b56bafd0abfd486be2709640055fef Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 19 Oct 2023 11:53:07 -0600 Subject: [PATCH 1/5] fix vet --- pkg/handlers/handlers_test.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pkg/handlers/handlers_test.go b/pkg/handlers/handlers_test.go index 91bd7c0731..da58db5481 100644 --- a/pkg/handlers/handlers_test.go +++ b/pkg/handlers/handlers_test.go @@ -1210,22 +1210,12 @@ var HandlerPolicyTests = map[string][]HandlerPolicyTest{ }, "HelmVM": {}, // Not implemented - "GenerateHelmVMNodeJoinCommandSecondary": { + "GenerateHelmVMNodeJoinCommand": { { Roles: []rbactypes.Role{rbac.ClusterAdminRole}, SessionRoles: []string{rbac.ClusterAdminRoleID}, Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { - handlerRecorder.GenerateHelmVMNodeJoinCommandSecondary(gomock.Any(), gomock.Any()) - }, - ExpectStatus: http.StatusOK, - }, - }, - "GenerateHelmVMNodeJoinCommandPrimary": { - { - Roles: []rbactypes.Role{rbac.ClusterAdminRole}, - SessionRoles: []string{rbac.ClusterAdminRoleID}, - Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { - handlerRecorder.GenerateHelmVMNodeJoinCommandPrimary(gomock.Any(), gomock.Any()) + handlerRecorder.GenerateHelmVMNodeJoinCommand(gomock.Any(), gomock.Any()) }, ExpectStatus: http.StatusOK, }, From 37231a73913a4723204bd212343f717a7378f617 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 19 Oct 2023 12:42:07 -0600 Subject: [PATCH 2/5] fix tests --- pkg/handlers/handlers_test.go | 20 ++++++++++++++++++++ pkg/handlers/interface.go | 1 + pkg/handlers/mock/mock.go | 12 ++++++++++++ 3 files changed, 33 insertions(+) diff --git a/pkg/handlers/handlers_test.go b/pkg/handlers/handlers_test.go index da58db5481..78cc84ee23 100644 --- a/pkg/handlers/handlers_test.go +++ b/pkg/handlers/handlers_test.go @@ -1252,6 +1252,26 @@ var HandlerPolicyTests = map[string][]HandlerPolicyTest{ ExpectStatus: http.StatusOK, }, }, + "GetHelmVMNode": { + { + Roles: []rbactypes.Role{rbac.ClusterAdminRole}, + SessionRoles: []string{rbac.ClusterAdminRoleID}, + Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { + handlerRecorder.GetHelmVMNode(gomock.Any(), gomock.Any()) + }, + ExpectStatus: http.StatusOK, + }, + }, + "GetK0sNodeJoinCommand": { + { + Roles: []rbactypes.Role{rbac.ClusterAdminRole}, + SessionRoles: []string{rbac.ClusterAdminRoleID}, + Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { + handlerRecorder.GetK0sNodeJoinCommand(gomock.Any(), gomock.Any()) + }, + ExpectStatus: http.StatusOK, + }, + }, // Prometheus "SetPrometheusAddress": { diff --git a/pkg/handlers/interface.go b/pkg/handlers/interface.go index 0a1fa800fe..81945a41ac 100644 --- a/pkg/handlers/interface.go +++ b/pkg/handlers/interface.go @@ -144,6 +144,7 @@ type KOTSHandler interface { DeleteHelmVMNode(w http.ResponseWriter, r *http.Request) GetHelmVMNodes(w http.ResponseWriter, r *http.Request) GetHelmVMNode(w http.ResponseWriter, r *http.Request) + GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) // Prometheus SetPrometheusAddress(w http.ResponseWriter, r *http.Request) diff --git a/pkg/handlers/mock/mock.go b/pkg/handlers/mock/mock.go index 0898775f70..8df1befd4c 100644 --- a/pkg/handlers/mock/mock.go +++ b/pkg/handlers/mock/mock.go @@ -778,6 +778,18 @@ func (mr *MockKOTSHandlerMockRecorder) GetHelmVMNodes(w, r interface{}) *gomock. return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHelmVMNodes", reflect.TypeOf((*MockKOTSHandler)(nil).GetHelmVMNodes), w, r) } +// GetK0sNodeJoinCommand mocks base method. +func (m *MockKOTSHandler) GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "GetK0sNodeJoinCommand", w, r) +} + +// GetK0sNodeJoinCommand indicates an expected call of GetK0sNodeJoinCommand. +func (mr *MockKOTSHandlerMockRecorder) GetK0sNodeJoinCommand(w, r interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetK0sNodeJoinCommand", reflect.TypeOf((*MockKOTSHandler)(nil).GetHelmVMNode), w, r) +} + // GetIdentityServiceConfig mocks base method. func (m *MockKOTSHandler) GetIdentityServiceConfig(w http.ResponseWriter, r *http.Request) { m.ctrl.T.Helper() From 959a9b7d9df05fb9df6fa385efeac37a2b31966a Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 19 Oct 2023 13:10:51 -0600 Subject: [PATCH 3/5] complete mock handler --- pkg/handlers/handlers_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/handlers/handlers_test.go b/pkg/handlers/handlers_test.go index 78cc84ee23..2df3be344a 100644 --- a/pkg/handlers/handlers_test.go +++ b/pkg/handlers/handlers_test.go @@ -1254,6 +1254,7 @@ var HandlerPolicyTests = map[string][]HandlerPolicyTest{ }, "GetHelmVMNode": { { + Vars: map[string]string{"nodeName": "node-name"}, Roles: []rbactypes.Role{rbac.ClusterAdminRole}, SessionRoles: []string{rbac.ClusterAdminRoleID}, Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { From 88bc9e10b7d325aeb02a90aab5c100ec6ffc2ba7 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 19 Oct 2023 13:33:14 -0600 Subject: [PATCH 4/5] more test --- pkg/handlers/handlers_test.go | 4 ++-- pkg/handlers/mock/mock.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/handlers/handlers_test.go b/pkg/handlers/handlers_test.go index 2df3be344a..9d4ee77a74 100644 --- a/pkg/handlers/handlers_test.go +++ b/pkg/handlers/handlers_test.go @@ -1210,12 +1210,12 @@ var HandlerPolicyTests = map[string][]HandlerPolicyTest{ }, "HelmVM": {}, // Not implemented - "GenerateHelmVMNodeJoinCommand": { + "GenerateK0sNodeJoinCommand": { { Roles: []rbactypes.Role{rbac.ClusterAdminRole}, SessionRoles: []string{rbac.ClusterAdminRoleID}, Calls: func(storeRecorder *mock_store.MockStoreMockRecorder, handlerRecorder *mock_handlers.MockKOTSHandlerMockRecorder) { - handlerRecorder.GenerateHelmVMNodeJoinCommand(gomock.Any(), gomock.Any()) + handlerRecorder.GenerateK0sNodeJoinCommand(gomock.Any(), gomock.Any()) }, ExpectStatus: http.StatusOK, }, diff --git a/pkg/handlers/mock/mock.go b/pkg/handlers/mock/mock.go index 8df1befd4c..e19e7c23df 100644 --- a/pkg/handlers/mock/mock.go +++ b/pkg/handlers/mock/mock.go @@ -448,8 +448,8 @@ func (m *MockKOTSHandler) GenerateK0sNodeJoinCommand(w http.ResponseWriter, r *h m.ctrl.Call(m, "GenerateK0sNodeJoinCommand", w, r) } -// GenerateHelmVMNodeJoinCommand indicates an expected call of GenerateHelmVMNodeJoinCommand. -func (mr *MockKOTSHandlerMockRecorder) GenerateHelmVMNodeJoinCommand(w, r interface{}) *gomock.Call { +// GenerateK0sNodeJoinCommand indicates an expected call of GenerateK0sNodeJoinCommand. +func (mr *MockKOTSHandlerMockRecorder) GenerateK0sNodeJoinCommand(w, r interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateK0sNodeJoinCommand", reflect.TypeOf((*MockKOTSHandler)(nil).GenerateK0sNodeJoinCommand), w, r) } From 07707ec5f3e363bb4c88b2b689224d714e7e3e41 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 19 Oct 2023 13:33:50 -0600 Subject: [PATCH 5/5] mockgen --- pkg/handlers/mock/mock.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/handlers/mock/mock.go b/pkg/handlers/mock/mock.go index e19e7c23df..2d47a3af6f 100644 --- a/pkg/handlers/mock/mock.go +++ b/pkg/handlers/mock/mock.go @@ -442,7 +442,7 @@ func (mr *MockKOTSHandlerMockRecorder) GarbageCollectImages(w, r interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GarbageCollectImages", reflect.TypeOf((*MockKOTSHandler)(nil).GarbageCollectImages), w, r) } -// GenerateHelmVMNodeJoinCommand mocks base method. +// GenerateK0sNodeJoinCommand mocks base method. func (m *MockKOTSHandler) GenerateK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) { m.ctrl.T.Helper() m.ctrl.Call(m, "GenerateK0sNodeJoinCommand", w, r) @@ -778,18 +778,6 @@ func (mr *MockKOTSHandlerMockRecorder) GetHelmVMNodes(w, r interface{}) *gomock. return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHelmVMNodes", reflect.TypeOf((*MockKOTSHandler)(nil).GetHelmVMNodes), w, r) } -// GetK0sNodeJoinCommand mocks base method. -func (m *MockKOTSHandler) GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "GetK0sNodeJoinCommand", w, r) -} - -// GetK0sNodeJoinCommand indicates an expected call of GetK0sNodeJoinCommand. -func (mr *MockKOTSHandlerMockRecorder) GetK0sNodeJoinCommand(w, r interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetK0sNodeJoinCommand", reflect.TypeOf((*MockKOTSHandler)(nil).GetHelmVMNode), w, r) -} - // GetIdentityServiceConfig mocks base method. func (m *MockKOTSHandler) GetIdentityServiceConfig(w http.ResponseWriter, r *http.Request) { m.ctrl.T.Helper() @@ -826,6 +814,18 @@ func (mr *MockKOTSHandlerMockRecorder) GetInstanceSnapshotConfig(w, r interface{ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstanceSnapshotConfig", reflect.TypeOf((*MockKOTSHandler)(nil).GetInstanceSnapshotConfig), w, r) } +// GetK0sNodeJoinCommand mocks base method. +func (m *MockKOTSHandler) GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "GetK0sNodeJoinCommand", w, r) +} + +// GetK0sNodeJoinCommand indicates an expected call of GetK0sNodeJoinCommand. +func (mr *MockKOTSHandlerMockRecorder) GetK0sNodeJoinCommand(w, r interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetK0sNodeJoinCommand", reflect.TypeOf((*MockKOTSHandler)(nil).GetK0sNodeJoinCommand), w, r) +} + // GetKotsadmRegistry mocks base method. func (m *MockKOTSHandler) GetKotsadmRegistry(w http.ResponseWriter, r *http.Request) { m.ctrl.T.Helper()