Skip to content

Commit

Permalink
add UT for validateCoordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
advancedxy committed Feb 6, 2023
1 parent 2a24fc9 commit 0acc053
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions deploy/kubernetes/operator/pkg/webhook/inspector/rss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -216,3 +217,63 @@ func TestValidateRSS(t *testing.T) {
})
}
}

func TestValidateCoordinator(t *testing.T) {
for _, tt := range []struct {
name string
coordinator *unifflev1alpha1.CoordinatorConfig
allowed bool
}{
{
name: "empty RPCNodePort",
coordinator: &unifflev1alpha1.CoordinatorConfig{
Count: pointer.Int32(2),
},
allowed: true,
},
{
name: "same number of RPCNodePort and HTTPNodePort",
coordinator: &unifflev1alpha1.CoordinatorConfig{
Count: pointer.Int32(2),
RPCNodePort: []int32{19996, 19997},
HTTPNodePort: []int32{19996, 19997},
},
allowed: true,
},
{
name: "different number of RPCNodePort and HTTPNodePort",
coordinator: &unifflev1alpha1.CoordinatorConfig{
Count: pointer.Int32(2),
RPCNodePort: []int32{19996, 19997, 19998},
HTTPNodePort: []int32{19991, 19992},
},
allowed: false,
},
{
name: "same number of RPCNodePort and HTTPNodePort but with different coordinator count",
coordinator: &unifflev1alpha1.CoordinatorConfig{
Count: pointer.Int32(1),
RPCNodePort: []int32{19996, 19997},
HTTPNodePort: []int32{19991, 19992},
},
allowed: false,
},
} {
t.Run(tt.name, func(t *testing.T) {
assertion := assert.New(t)
tt.coordinator.ExcludeNodesFilePath = "/exclude_nodes"
tt.coordinator.CommonConfig = &unifflev1alpha1.CommonConfig{
RSSPodSpec: &unifflev1alpha1.RSSPodSpec{
LogHostPath: "",
HostPathMounts: map[string]string{},
},
}
err := validateCoordinator(tt.coordinator)
if tt.allowed {
assertion.Nil(err, "expected allowed, but got error: %v", err)
} else {
assertion.Error(err, "expected denied, but got accepted")
}
})
}
}

0 comments on commit 0acc053

Please sign in to comment.