diff options
author | Julien Dessaux | 2021-04-05 17:52:31 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-04-05 17:52:31 +0200 |
commit | 1ffc9c42054e208a01d3e70e6b6f3e1781e798f8 (patch) | |
tree | 721f202dcf46fb5e9c181013237e4da9d27f796a /config/config_test.go | |
parent | Reworked error handling for better and simpler tests (diff) | |
download | trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.gz trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.bz2 trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.zip |
Moved code around to conform best practices
Diffstat (limited to 'config/config_test.go')
-rw-r--r-- | config/config_test.go | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/config/config_test.go b/config/config_test.go deleted file mode 100644 index 3904b5d..0000000 --- a/config/config_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package config - -import ( - "reflect" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestLoadFile(t *testing.T) { - // Minimal yaml file - minimalConfig := Config{ - Address: "127.0.0.2", - Port: "8082", - Token: "12345678-9abc-def0-1234-56789abcdef0", - } - - // Minimal yaml file with hostname resolving - minimalConfigWithResolving := Config{ - Address: "localhost", - Port: "8082", - Token: "12345678-9abc-def0-1234-56789abcdef0", - } - - // Test cases - testCases := []struct { - name string - input string - expected *Config - expectedError interface{} - }{ - {"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}, - } - for _, tc := range testCases { - t.Run(tc.name, func(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)) - } else { - require.NoError(t, err) - } - assert.Equal(t, tc.expected, valid, "Invalid value") - }) - } -} |