Skip to content

Commit

Permalink
chore: add test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Patidar <akshaypatidar1999@gmail.com>
  • Loading branch information
akshaypatidar1999 committed Oct 19, 2024
1 parent a168284 commit ce5d078
Showing 1 changed file with 68 additions and 4 deletions.
72 changes: 68 additions & 4 deletions controllers/autoneg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ var statusTests = []struct {
true,
true,
},
{
"valid autoneg status without autoneg",
map[string]string{
autonegStatusAnnotation: validStatus,
},
true,
false,
},
}

var oldStatusTests = []struct {
Expand Down Expand Up @@ -256,12 +264,21 @@ var oldStatusTests = []struct {
true,
false,
},
{
"(legacy) valid autoneg status without autoneg",
map[string]string{
oldAutonegStatusAnnotation: validStatus,
},
true,
false,
},
}

func TestGetStatuses(t *testing.T) {
var serviceReconciler = ServiceReconciler{
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
DeregisterNEGsOnAnnotationRemoval: true,
}
for _, st := range statusTests {
_, valid, err := getStatuses("ns", "test", st.annotations, &serviceReconciler)
Expand All @@ -282,8 +299,9 @@ func TestGetStatuses(t *testing.T) {

func TestGetOldStatuses(t *testing.T) {
var serviceReconciler = ServiceReconciler{
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
DeregisterNEGsOnAnnotationRemoval: true,
}
for _, st := range oldStatusTests {
_, valid, err := getStatuses("ns", "test", st.annotations, &serviceReconciler)
Expand Down Expand Up @@ -340,6 +358,52 @@ func TestGetStatusesServiceNameAllowed(t *testing.T) {
}
}

func TestGetStatusesOnlyAutonegStatusAnnotation(t *testing.T) {
var serviceReconciler = ServiceReconciler{
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
DeregisterNEGsOnAnnotationRemoval: true,
}
statuses, valid, err := getStatuses("ns", "test", map[string]string{autonegStatusAnnotation: validAutonegStatus}, &serviceReconciler)
if err != nil {
t.Errorf("Expected no error, got one: %v", err)
}
if !valid {
t.Errorf("Expected autoneg status config, got none")
}

if !statuses.newConfig {
t.Errorf("Expected new autoneg config")
}
if statuses.config.BackendServices != nil {
t.Errorf("Expected nil backend services")
}

}

func TestGetStatusesOnlyOldAutonegStatusAnnotation(t *testing.T) {
var serviceReconciler = ServiceReconciler{
ServiceNameTemplate: "{namespace}-{name}-{port}-{hash}",
AllowServiceName: true,
DeregisterNEGsOnAnnotationRemoval: true,
}
statuses, valid, err := getStatuses("ns", "test", map[string]string{oldAutonegStatusAnnotation: validAutonegStatus}, &serviceReconciler)
if err != nil {
t.Errorf("Expected no error, got one: %v", err)
}
if !valid {
t.Errorf("Expected old autoneg status config, got none")
}

if statuses.newConfig {
t.Errorf("Expected old autoneg config")
}
if statuses.oldConfig.Name != "" {
t.Errorf("Expected empty old autoneg config")
}

}

func TestDefaultMaxRatePerEndpointWhenOverrideIsSet(t *testing.T) {
var serviceReconciler = ServiceReconciler{
ServiceNameTemplate: "{namespace}-{name}-{port}",
Expand Down

0 comments on commit ce5d078

Please sign in to comment.