diff options
author | Julien Dessaux | 2021-09-15 21:22:02 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-15 21:22:02 +0200 |
commit | 84ba078a40cd2ed127b6df5137b1e0bd2389b2f3 (patch) | |
tree | ba39a5798e70f8ad214a8b594b0fb8a0cbef0d26 /pkg/config/config_test.go | |
parent | Finished rewriting database package tests for consistency (diff) | |
download | trains-84ba078a40cd2ed127b6df5137b1e0bd2389b2f3.tar.gz trains-84ba078a40cd2ed127b6df5137b1e0bd2389b2f3.tar.bz2 trains-84ba078a40cd2ed127b6df5137b1e0bd2389b2f3.zip |
Rewrote config tests for consistency
Diffstat (limited to '')
-rw-r--r-- | pkg/config/config_test.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 43d4a48..ee130f3 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -1,10 +1,8 @@ package config import ( - "reflect" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,14 +33,14 @@ func TestLoadFile(t *testing.T) { name string input string expected *Config - expectedError interface{} + expectedError error }{ - {"Non existant file", "test_data/non-existant", nil, &OpenError{}}, - {"Invalid file content", "test_data/invalid.yaml", nil, &DecodeError{}}, - {"Invalid address should fail to load", "test_data/invalid_address.yaml", nil, &InvalidAddressError{}}, - {"Unresolvable address should fail to load", "test_data/invalid_address_unresolvable.yaml", nil, &InvalidAddressError{}}, - {"Invalid port should fail to load", "test_data/invalid_port.yaml", nil, &InvalidPortError{}}, - {"Invalid token should fail to load", "test_data/invalid_token.yaml", nil, &InvalidTokenError{}}, + {"Non existant file", "test_data/non-existant", nil, OpenError{}}, + {"Invalid file content", "test_data/invalid.yaml", nil, DecodeError{}}, + {"Invalid address should fail to load", "test_data/invalid_address.yaml", nil, InvalidAddressError{}}, + {"Unresolvable address should fail to load", "test_data/invalid_address_unresolvable.yaml", nil, InvalidAddressError{}}, + {"Invalid port should fail to load", "test_data/invalid_port.yaml", nil, InvalidPortError{}}, + {"Invalid token should fail to load", "test_data/invalid_token.yaml", nil, InvalidTokenError{}}, {"Minimal config", "test_data/minimal.yaml", &minimalConfig, nil}, {"Minimal config with resolving", "test_data/minimal_with_hostname.yaml", &minimalConfigWithResolving, nil}, {"Complete config", "test_data/complete.yaml", &completeConfig, nil}, @@ -52,12 +50,12 @@ func TestLoadFile(t *testing.T) { valid, err := LoadFile(tc.input) if tc.expectedError != nil { require.Error(t, err) - assert.Equalf(t, reflect.TypeOf(err), reflect.TypeOf(tc.expectedError), "Invalid error type. Got %s but expected %s", reflect.TypeOf(err), reflect.TypeOf(tc.expectedError)) + requireErrorTypeMatch(t, err, tc.expectedError) require.Nil(t, valid) } else { require.NoError(t, err) } - assert.Equal(t, tc.expected, valid, "Invalid value") + require.Equal(t, tc.expected, valid, "Invalid value") }) } } |