Skip to content

Commit

Permalink
pkg/karmadactl/addons: unit test install addons
Browse files Browse the repository at this point in the history
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 <mohamedmohey2352@gmail.com>
  • Loading branch information
mohamedawnallah committed Oct 29, 2024
1 parent 6c6281f commit f7feac0
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/karmadactl/addons/install/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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)
}
})
}
}

0 comments on commit f7feac0

Please sign in to comment.