Merge pull request #5754 from mohamedawnallah/unitTestInstallAddon

pkg/karmadactl/addons: unit test install addons
This commit is contained in:
karmada-bot 2024-12-04 17:17:09 +08:00 committed by GitHub
commit 616a95e0d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 71 additions and 0 deletions

View File

@ -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)
}
})
}
}