github.com/resonatecoop/user-api@v1.0.0-13.0.20220915120639-05dc9c04014a/pkg/config/config_test.go (about) 1 package config_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "user-api/pkg/config" 9 ) 10 11 func TestLoad(t *testing.T) { 12 cases := []struct { 13 name string 14 path string 15 wantData *config.Configuration 16 wantErr bool 17 }{ 18 { 19 name: "does not exist", 20 path: "no", 21 wantErr: true, 22 }, 23 { 24 name: "invalid format", 25 path: "testdata/invalid.yaml", 26 wantErr: true, 27 }, 28 { 29 name: "success", 30 path: "testdata/success.yaml", 31 wantData: &config.Configuration{ 32 Server: config.Server{ 33 Port: ":8080", 34 ReadTimeoutSeconds: 31, 35 WriteTimeoutSeconds: 30, 36 }, 37 DB: config.DatabaseEnv{ 38 Dev: config.Database{ 39 PSN: "postgre", 40 LogQueries: true, 41 TimeoutSeconds: 10, 42 }, 43 Test: config.Database{ 44 PSN: "postgre", 45 LogQueries: true, 46 TimeoutSeconds: 10, 47 }, 48 }, 49 JWT: config.JWT{ 50 Secret: "changedvalue", 51 Duration: 15, 52 Algorithm: "HS256", 53 }, 54 App: config.Application{ 55 MinPasswordStrength: 1, 56 }, 57 OpenAPI: config.OpenAPI{ 58 Username: "twisk", 59 Password: "twisk", 60 }, 61 }, 62 wantErr: false, 63 }, 64 } 65 66 for _, tc := range cases { 67 t.Run(tc.name, func(t *testing.T) { 68 cfg, err := config.Load(tc.path) 69 assert.Equal(t, tc.wantData, cfg) 70 assert.Equal(t, tc.wantErr, err != nil) 71 }) 72 } 73 }