Skip to content

Commit

Permalink
Add test for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
LorcanMcVeigh committed Jul 23, 2019
1 parent 742676a commit e22d797
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/configuration/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func validateUpstreams(upstreams []v1alpha1.Upstream, fieldPath *field.Path, isP
allErrs = append(allErrs, validateTime(u.ProxyReadTimeout, idxPath.Child("read-timeout"))...)
allErrs = append(allErrs, validateTime(u.ProxySendTimeout, idxPath.Child("send-timeout"))...)
allErrs = append(allErrs, validateNextUpstream(u.ProxyNextUpstream, idxPath.Child("next-upstream"))...)
allErrs = append(allErrs, validateTime(u.ProxyNextUpstream, idxPath.Child("next-upstream-timeout"))...)
allErrs = append(allErrs, validateTime(u.ProxyNextUpstreamTimeout, idxPath.Child("next-upstream-timeout"))...)
allErrs = append(allErrs, validatePositiveIntOrZero(u.ProxyNextUpstreamTries, idxPath.Child("next-upstream-tries"))...)

allErrs = append(allErrs, validateUpstreamLBMethod(u.LBMethod, idxPath.Child("lb-method"), isPlus)...)
Expand Down
111 changes: 90 additions & 21 deletions pkg/apis/configuration/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ func TestValidateUpstreams(t *testing.T) {
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
Name: "upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "error timeout",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
{
Name: "upstream2",
Service: "test-2",
Port: 80,
Name: "upstream2",
Service: "test-2",
Port: 80,
ProxyNextUpstream: "http_404",
ProxyNextUpstreamTimeout: "3s",
ProxyNextUpstreamTries: createPointerFromInt(15),
},
},
expectedUpstreamNames: map[string]sets.Empty{
Expand Down Expand Up @@ -171,9 +177,12 @@ func TestValidateUpstreamsFails(t *testing.T) {
{
upstreams: []v1alpha1.Upstream{
{
Name: "@upstream1",
Service: "test-1",
Port: 80,
Name: "@upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "http_502",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: sets.String{},
Expand All @@ -182,9 +191,12 @@ func TestValidateUpstreamsFails(t *testing.T) {
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "@test-1",
Port: 80,
Name: "upstream1",
Service: "@test-1",
Port: 80,
ProxyNextUpstream: "error timeout",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: map[string]sets.Empty{
Expand All @@ -195,9 +207,12 @@ func TestValidateUpstreamsFails(t *testing.T) {
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 0,
Name: "upstream1",
Service: "test-1",
Port: 0,
ProxyNextUpstream: "error timeout",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: map[string]sets.Empty{
Expand All @@ -208,21 +223,75 @@ func TestValidateUpstreamsFails(t *testing.T) {
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
Name: "upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "error timeout",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
{
Name: "upstream1",
Service: "test-2",
Port: 80,
Name: "upstream1",
Service: "test-2",
Port: 80,
ProxyNextUpstream: "error timeout",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
},
msg: "duplicated upstreams",
},
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "https_504",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
},
msg: "invalid next upstream syntax",
},
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "http_504",
ProxyNextUpstreamTimeout: "-2s",
ProxyNextUpstreamTries: createPointerFromInt(5),
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
},
msg: "invalid upstream timeout value",
},
{
upstreams: []v1alpha1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
ProxyNextUpstream: "https_504",
ProxyNextUpstreamTimeout: "10s",
ProxyNextUpstreamTries: createPointerFromInt(-1),
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": sets.Empty{},
},
msg: "invalid upstream tries value",
},
}

isPlus := false
Expand Down

0 comments on commit e22d797

Please sign in to comment.