From 4ab6bff3b0d3f93e0d4d16c7e82e6e3ba2c577f0 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Tue, 29 Oct 2024 14:32:19 +0300 Subject: [PATCH] pkg/karmadactl/addons: unit test install addons In this commit, we unit test install addons to make sure the following addons `karmada-descheduler`, `karmada-metrics-adapter`, `karmada-scheduler-estimator`, and `karmada-search` are already configured. Signed-off-by: Mohamed Awnallah --- pkg/karmadactl/addons/install/install_test.go | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 pkg/karmadactl/addons/install/install_test.go diff --git a/pkg/karmadactl/addons/install/install_test.go b/pkg/karmadactl/addons/install/install_test.go new file mode 100644 index 000000000..395281116 --- /dev/null +++ b/pkg/karmadactl/addons/install/install_test.go @@ -0,0 +1,71 @@ +/* +Copyright 2024 The Karmada Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package install + +import ( + "reflect" + "testing" + + "github.com/karmada-io/karmada/pkg/karmadactl/addons/descheduler" + "github.com/karmada-io/karmada/pkg/karmadactl/addons/estimator" + addonsinit "github.com/karmada-io/karmada/pkg/karmadactl/addons/init" + "github.com/karmada-io/karmada/pkg/karmadactl/addons/metricsadapter" + "github.com/karmada-io/karmada/pkg/karmadactl/addons/search" +) + +func TestInstall(t *testing.T) { + // Call the function to install addons. + Install() + + tests := []struct { + name string + key string + expectedAddon interface{} + }{ + { + name: "Install_WithKarmadaDeschedulerAddon_Installed", + key: "karmada-descheduler", + expectedAddon: descheduler.AddonDescheduler, + }, + { + name: "Install_WithKarmadaMetricsAdapterAddon_Installed", + key: "karmada-metrics-adapter", + expectedAddon: metricsadapter.AddonMetricsAdapter, + }, + { + name: "Install_WithKarmadaSchedulerEstimatorAddon_Installed", + key: "karmada-scheduler-estimator", + expectedAddon: estimator.AddonEstimator, + }, + { + name: "Install_WithKarmadaSearchAddon_Installed", + key: "karmada-search", + expectedAddon: search.AddonSearch, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actualAddon, exists := addonsinit.Addons[tt.key] + if !exists { + t.Fatalf("Expected addon %s to be registered, but it was not found", tt.key) + } + if !reflect.DeepEqual(actualAddon, tt.expectedAddon) { + t.Errorf("Expected addon %s to be %v, but got %v", tt.key, tt.expectedAddon, actualAddon) + } + }) + } +}