Add test for bad configuration
This commit is contained in:
@ -6,8 +6,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseConfigBytes(t *testing.T) {
|
||||
config := parseConfigBytes([]byte(`
|
||||
func TestParseAndValidateConfigBytes(t *testing.T) {
|
||||
config, err := parseAndValidateConfigBytes([]byte(`
|
||||
services:
|
||||
- name: twinnation
|
||||
url: https://twinnation.org/actuator/health
|
||||
@ -20,6 +20,9 @@ services:
|
||||
- "$STATUS != 400"
|
||||
- "$STATUS != 500"
|
||||
`))
|
||||
if err != nil {
|
||||
t.Error("No error should've been returned")
|
||||
}
|
||||
if len(config.Services) != 2 {
|
||||
t.Error("Should have returned two services")
|
||||
}
|
||||
@ -44,14 +47,17 @@ services:
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseConfigBytesDefault(t *testing.T) {
|
||||
config := parseConfigBytes([]byte(`
|
||||
func TestParseAndValidateConfigBytesDefault(t *testing.T) {
|
||||
config, err := parseAndValidateConfigBytes([]byte(`
|
||||
services:
|
||||
- name: twinnation
|
||||
url: https://twinnation.org/actuator/health
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
`))
|
||||
if err != nil {
|
||||
t.Error("No error should've been returned")
|
||||
}
|
||||
if config.Services[0].Url != "https://twinnation.org/actuator/health" {
|
||||
t.Errorf("URL should have been %s", "https://twinnation.org/actuator/health")
|
||||
}
|
||||
@ -59,3 +65,19 @@ services:
|
||||
t.Errorf("Interval should have been %s, because it is the default value", 10*time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAndValidateBadConfigBytes(t *testing.T) {
|
||||
_, err := parseAndValidateConfigBytes([]byte(`
|
||||
badconfig:
|
||||
- asdsa: w0w
|
||||
usadasdrl: asdxzczxc
|
||||
asdas:
|
||||
- soup
|
||||
`))
|
||||
if err == nil {
|
||||
t.Error("An error should've been returned")
|
||||
}
|
||||
if err != ErrNoServiceInConfig {
|
||||
t.Error("The error returned should have been of type ErrNoServiceInConfig")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user