Skip to content

Commit

Permalink
fixed failing tests according to golang 1.14.4 version
Browse files Browse the repository at this point in the history
added more tests

linter fix
  • Loading branch information
alexey-kremsa-globant committed Jun 8, 2020
1 parent 4445774 commit fa6e359
Showing 1 changed file with 59 additions and 17 deletions.
76 changes: 59 additions & 17 deletions pkg/fleetautoscalers/fleetautoscalers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func TestApplyWebhookPolicy(t *testing.T) {
expected: expected{
replicas: 0,
limited: false,
err: "parse )1golang.org/: invalid URI for request",
err: "parse \")1golang.org/\": invalid URI for request",
},
},
{
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestApplyWebhookPolicy(t *testing.T) {
expected: expected{
replicas: 0,
limited: false,
err: "Post http://127.0.0.1:1: dial tcp 127.0.0.1:1: connect: connection refused",
err: "Post \"http://127.0.0.1:1\": dial tcp 127.0.0.1:1: connect: connection refused",
},
},
{
Expand Down Expand Up @@ -520,21 +520,6 @@ func TestApplyWebhookPolicy(t *testing.T) {
err: "invalid character 'i' looking for beginning of value",
},
},
{
description: "Nil URL, empty namespace - default one should be used, no such host err is returned",
webhookPolicy: &autoscalingv1.WebhookPolicy{
Service: &admregv1b.ServiceReference{
Name: "service1",
Namespace: "",
Path: &url,
},
},
expected: expected{
replicas: 0,
limited: false,
err: "Post http://service1.default.svc:8000/scale: dial tcp: lookup service1.default.svc: no such host",
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -626,3 +611,60 @@ func TestCreateURL(t *testing.T) {
})
}
}

func TestBuildURLFromWebhookPolicyNoNamespace(t *testing.T) {
url := "/testurl"

type expected struct {
url string
err string
}

var testCases = []struct {
description string
webhookPolicy *autoscalingv1.WebhookPolicy
expected expected
}{
{
description: "No namespace provided, default should be used",
webhookPolicy: &autoscalingv1.WebhookPolicy{
Service: &admregv1b.ServiceReference{
Name: "service1",
Namespace: "",
Path: &url,
},
},
expected: expected{
url: "http://service1.default.svc:8000/testurl",
err: "",
},
},
{
description: "No url provided, empty string should be used",
webhookPolicy: &autoscalingv1.WebhookPolicy{
Service: &admregv1b.ServiceReference{
Name: "service1",
Namespace: "test",
Path: nil,
},
},
expected: expected{
url: "http://service1.test.svc:8000",
err: "",
},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
url, err := buildURLFromWebhookPolicy(tc.webhookPolicy)

if tc.expected.err != "" && assert.NotNil(t, err) {
assert.Equal(t, tc.expected.err, err.Error())
} else {
assert.Nil(t, err)
assert.Equal(t, tc.expected.url, url.String())
}
})
}
}

0 comments on commit fa6e359

Please sign in to comment.