Skip to content

Commit

Permalink
TEST/MINOR: Automatically get the number of rules
Browse files Browse the repository at this point in the history
This avoids having to update the tests each time we add new
configuration rules.
  • Loading branch information
oliwer committed Mar 11, 2024
1 parent a11e86e commit 019d7ed
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
11 changes: 8 additions & 3 deletions test/http_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ func TestCreateEditDeleteHTTPCheck(t *testing.T) {
}

// TestDeleteHTTPRequest
err = clientTest.DeleteHTTPCheck(14, configuration.BackendParentName, "test", "", version)
_, checks, err := clientTest.GetHTTPChecks(configuration.BackendParentName, "test", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(checks)) - 1
err = clientTest.DeleteHTTPCheck(N, configuration.BackendParentName, "test", "", version)
if err != nil {
t.Error(err.Error())
} else {
Expand All @@ -225,9 +230,9 @@ func TestCreateEditDeleteHTTPCheck(t *testing.T) {
t.Error("Version not incremented")
}

_, _, err = clientTest.GetHTTPCheck(14, configuration.BackendParentName, "test", "")
_, _, err = clientTest.GetHTTPCheck(N, configuration.BackendParentName, "test", "")
if err == nil {
t.Error("DeleteHTTPCheck failed, HTTP check 13 still exists")
t.Errorf("DeleteHTTPCheck failed, HTTP check %d still exists", N)
}

err = clientTest.DeleteHTTPCheck(5, configuration.BackendParentName, "test_2", "", version)
Expand Down
11 changes: 8 additions & 3 deletions test/http_error_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ func TestCreateEditDeleteHTTPErrorRule(t *testing.T) {
t.Error("deleting http-error rule failed - http-error rule 0 still exists")
}

err = clientTest.DeleteHTTPErrorRule(1, configuration.DefaultsParentName, "", "", version)
_, rules, err := clientTest.GetHTTPErrorRules(configuration.DefaultsParentName, "", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(rules)) - 1
err = clientTest.DeleteHTTPErrorRule(N, configuration.DefaultsParentName, "", "", version)
if err != nil {
t.Error(err.Error())
} else {
Expand All @@ -238,9 +243,9 @@ func TestCreateEditDeleteHTTPErrorRule(t *testing.T) {
t.Error("Version not incremented")
}

_, _, err = clientTest.GetHTTPErrorRule(1, configuration.DefaultsParentName, "", "")
_, _, err = clientTest.GetHTTPErrorRule(N, configuration.DefaultsParentName, "", "")
if err == nil {
t.Error("deleting http-error rule failed - http-error rule 1 still exists")
t.Errorf("deleting http-error rule failed - http-error rule %d still exists", N)
}

err = clientTest.DeleteHTTPErrorRule(3, configuration.BackendParentName, "test_2", "", version)
Expand Down
6 changes: 5 additions & 1 deletion test/http_request_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ func TestCreateEditDeleteHTTPRequestRule(t *testing.T) {
}

// TestDeleteHTTPRequest
N := int64(51) // number of http-request rules on frontend "test"
_, rules, err := clientTest.GetHTTPRequestRules(configuration.FrontendParentName, "test", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(rules)) - 1
err = clientTest.DeleteHTTPRequestRule(N, configuration.FrontendParentName, "test", "", version)
if err != nil {
t.Error(err.Error())
Expand Down
11 changes: 8 additions & 3 deletions test/http_response_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func TestCreateEditDeleteHTTPResponseRule(t *testing.T) {
}

// TestDeleteHTTPResponse
err = clientTest.DeleteHTTPResponseRule(35, configuration.FrontendParentName, "test", "", version)
_, rules, err := clientTest.GetHTTPResponseRules(configuration.FrontendParentName, "test", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(rules)) - 1
err = clientTest.DeleteHTTPResponseRule(N, configuration.FrontendParentName, "test", "", version)
if err != nil {
t.Error(err.Error())
} else {
Expand All @@ -182,9 +187,9 @@ func TestCreateEditDeleteHTTPResponseRule(t *testing.T) {
t.Error("Version not incremented")
}

_, _, err = clientTest.GetHTTPResponseRule(35, configuration.FrontendParentName, "test", "")
_, _, err = clientTest.GetHTTPResponseRule(N, configuration.FrontendParentName, "test", "")
if err == nil {
t.Error("DeleteHTTPResponseRule failed, HTTPResponse Rule 35 still exists")
t.Errorf("DeleteHTTPResponseRule failed, HTTPResponse Rule %d still exists", N)
}

err = clientTest.DeleteHTTPResponseRule(2, configuration.BackendParentName, "test_2", "", version)
Expand Down
6 changes: 5 additions & 1 deletion test/tcp_response_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ func TestCreateEditDeleteTCPResponseRule(t *testing.T) {
}

// TestDeleteTCPResponse
N := int64(20) // number of tcp-response rules in backend "test"
_, rules, err := clientTest.GetTCPResponseRules("test", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(rules)) - 1
err = clientTest.DeleteTCPResponseRule(N, "test", "", version)
if err != nil {
t.Error(err.Error())
Expand Down

0 comments on commit 019d7ed

Please sign in to comment.