-
Notifications
You must be signed in to change notification settings - Fork 70
/
config_test.go
26 lines (22 loc) · 962 Bytes
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package courier_test
import (
"testing"
"github.com/nyaruka/courier"
"github.com/stretchr/testify/assert"
)
var invalidConfigTestCases = []struct {
config *courier.Config
expectedError string
}{
{config: &courier.Config{DB: ":foo", Redis: "redis:localhost/23"}, expectedError: "Field validation for 'DB' failed on the 'url' tag"},
{config: &courier.Config{DB: "mysql:test", Redis: "redis:localhost/23"}, expectedError: "Field validation for 'DB' failed on the 'startswith' tag"},
{config: &courier.Config{DB: "postgres://courier:courier@localhost:5432/courier", Redis: ":foo"}, expectedError: "Field validation for 'Redis' failed on the 'url' tag"},
}
func TestConfigValidate(t *testing.T) {
for _, tc := range invalidConfigTestCases {
err := tc.config.Validate()
if assert.Error(t, err, "expected error for config %v", tc.config) {
assert.Contains(t, err.Error(), tc.expectedError, "error mismatch for config %v", tc.config)
}
}
}