Fix failing tests

This commit is contained in:
TwinProduction 2021-05-18 23:27:43 -04:00
parent db23bd9073
commit 263b2f0f94
3 changed files with 40 additions and 24 deletions

View File

@ -221,8 +221,7 @@ services:
} }
func TestParseAndValidateConfigBytesWithInvalidPort(t *testing.T) { func TestParseAndValidateConfigBytesWithInvalidPort(t *testing.T) {
defer func() { recover() }() _, err := parseAndValidateConfigBytes([]byte(`
_, _ = parseAndValidateConfigBytes([]byte(`
web: web:
port: 65536 port: 65536
address: 127.0.0.1 address: 127.0.0.1
@ -232,7 +231,9 @@ services:
conditions: conditions:
- "[STATUS] == 200" - "[STATUS] == 200"
`)) `))
t.Fatal("Should've panicked because the configuration specifies an invalid port value") if err == nil {
t.Fatal("Should've returned an error because the configuration specifies an invalid port value")
}
} }
func TestParseAndValidateConfigBytesWithMetricsAndCustomUserAgentHeader(t *testing.T) { func TestParseAndValidateConfigBytesWithMetricsAndCustomUserAgentHeader(t *testing.T) {
@ -1028,8 +1029,7 @@ services:
} }
func TestParseAndValidateConfigBytesWithInvalidSecurityConfig(t *testing.T) { func TestParseAndValidateConfigBytesWithInvalidSecurityConfig(t *testing.T) {
defer func() { recover() }() _, err := parseAndValidateConfigBytes([]byte(`
_, _ = parseAndValidateConfigBytes([]byte(`
security: security:
basic: basic:
username: "admin" username: "admin"
@ -1040,7 +1040,9 @@ services:
conditions: conditions:
- "[STATUS] == 200" - "[STATUS] == 200"
`)) `))
t.Error("Function should've panicked") if err == nil {
t.Error("Function should've returned an error")
}
} }
func TestParseAndValidateConfigBytesWithValidSecurityConfig(t *testing.T) { func TestParseAndValidateConfigBytesWithValidSecurityConfig(t *testing.T) {
@ -1161,8 +1163,7 @@ kubernetes:
} }
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryButNoServiceTemplate(t *testing.T) { func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryButNoServiceTemplate(t *testing.T) {
defer func() { recover() }() _, err := parseAndValidateConfigBytes([]byte(`
_, _ = parseAndValidateConfigBytes([]byte(`
kubernetes: kubernetes:
cluster-mode: "mock" cluster-mode: "mock"
auto-discover: true auto-discover: true
@ -1171,12 +1172,13 @@ kubernetes:
hostname-suffix: ".default.svc.cluster.local" hostname-suffix: ".default.svc.cluster.local"
target-path: "/health" target-path: "/health"
`)) `))
t.Error("Function should've panicked because providing a service-template is mandatory") if err == nil {
t.Error("Function should've returned an error because providing a service-template is mandatory")
}
} }
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryUsingClusterModeIn(t *testing.T) { func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryUsingClusterModeIn(t *testing.T) {
defer func() { recover() }() _, err := parseAndValidateConfigBytes([]byte(`
_, _ = parseAndValidateConfigBytes([]byte(`
kubernetes: kubernetes:
cluster-mode: "in" cluster-mode: "in"
auto-discover: true auto-discover: true
@ -1189,8 +1191,9 @@ kubernetes:
hostname-suffix: ".default.svc.cluster.local" hostname-suffix: ".default.svc.cluster.local"
target-path: "/health" target-path: "/health"
`)) `))
// TODO: find a way to test this? if err == nil {
t.Error("Function should've panicked because testing with ClusterModeIn isn't supported") t.Error("Function should've returned an error because testing with ClusterModeIn isn't supported")
}
} }
func TestGetAlertingProviderByAlertType(t *testing.T) { func TestGetAlertingProviderByAlertType(t *testing.T) {

View File

@ -109,8 +109,10 @@ func TestService_ValidateAndSetDefaultsWithNoDNSQueryName(t *testing.T) {
QueryType: "A", QueryType: "A",
QueryName: "", QueryName: "",
} }
dns.validateAndSetDefault() err := dns.validateAndSetDefault()
t.Fatal("Should've panicked because service`s dns didn't have a query name, which is a mandatory field for dns") if err == nil {
t.Fatal("Should've returned an error because service`s dns didn't have a query name, which is a mandatory field for dns")
}
} }
func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) { func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) {
@ -119,6 +121,8 @@ func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) {
QueryType: "B", QueryType: "B",
QueryName: "example.com", QueryName: "example.com",
} }
dns.validateAndSetDefault() err := dns.validateAndSetDefault()
t.Fatal("Should've panicked because service`s dns query type is invalid, it needs to be a valid query name like A, AAAA, CNAME...") if err == nil {
t.Fatal("Should've returned an error because service`s dns query type is invalid, it needs to be a valid query name like A, AAAA, CNAME...")
}
} }

View File

@ -49,8 +49,10 @@ func TestService_ValidateAndSetDefaultsWithNoName(t *testing.T) {
URL: "http://example.com", URL: "http://example.com",
Conditions: []*Condition{&condition}, Conditions: []*Condition{&condition},
} }
service.ValidateAndSetDefaults() err := service.ValidateAndSetDefaults()
t.Fatal("Should've panicked because service didn't have a name, which is a mandatory field") if err == nil {
t.Fatal("Should've returned an error because service didn't have a name, which is a mandatory field")
}
} }
func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) { func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) {
@ -61,8 +63,10 @@ func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) {
URL: "", URL: "",
Conditions: []*Condition{&condition}, Conditions: []*Condition{&condition},
} }
service.ValidateAndSetDefaults() err := service.ValidateAndSetDefaults()
t.Fatal("Should've panicked because service didn't have an url, which is a mandatory field") if err == nil {
t.Fatal("Should've returned an error because service didn't have an url, which is a mandatory field")
}
} }
func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) { func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) {
@ -72,8 +76,10 @@ func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) {
URL: "http://example.com", URL: "http://example.com",
Conditions: nil, Conditions: nil,
} }
service.ValidateAndSetDefaults() err := service.ValidateAndSetDefaults()
t.Fatal("Should've panicked because service didn't have at least 1 condition") if err == nil {
t.Fatal("Should've returned an error because service didn't have at least 1 condition")
}
} }
func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) { func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
@ -87,7 +93,10 @@ func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
}, },
Conditions: []*Condition{&conditionSuccess}, Conditions: []*Condition{&conditionSuccess},
} }
service.ValidateAndSetDefaults() err := service.ValidateAndSetDefaults()
if err != nil {
}
if service.DNS.QueryName != "example.com." { if service.DNS.QueryName != "example.com." {
t.Error("Service.dns.query-name should be formatted with . suffix") t.Error("Service.dns.query-name should be formatted with . suffix")
} }