(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCreatingNewValidation(t *testing.T) { |
| 14 | envs := []string{ |
| 15 | "POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_PORT", "POSTGRES_DB", "POSTGRES_HOST", "POSTGRES_SSLMODE", |
| 16 | } |
| 17 | |
| 18 | fullSetup := func() { |
| 19 | os.Setenv("POSTGRES_USER", "user") |
| 20 | os.Setenv("POSTGRES_PASSWORD", "password") |
| 21 | os.Setenv("POSTGRES_PORT", "5432") |
| 22 | os.Setenv("POSTGRES_DB", "database") |
| 23 | os.Setenv("POSTGRES_HOST", "database.com") |
| 24 | os.Setenv("POSTGRES_SSLMODE", "disable") |
| 25 | } |
| 26 | |
| 27 | clear := func() { |
| 28 | for _, env := range envs { |
| 29 | os.Unsetenv(env) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | testCases := []struct { |
| 34 | Description string |
| 35 | Setup func() |
| 36 | ExpectedCfg *config.Database |
| 37 | ExpectedErr error |
| 38 | }{ |
| 39 | { |
| 40 | Description: "testing a complete env setup", |
| 41 | Setup: func() { |
| 42 | fullSetup() |
| 43 | }, |
| 44 | ExpectedCfg: &config.Database{ |
| 45 | Username: "user", |
| 46 | Password: "password", |
| 47 | Port: 5432, |
| 48 | Host: "database.com", |
| 49 | DBName: "database", |
| 50 | SSLMode: "disable", |
| 51 | }, |
| 52 | }, |
| 53 | { |
| 54 | Description: "no setup", |
| 55 | Setup: func() { |
| 56 | clear() |
| 57 | }, |
| 58 | ExpectedErr: fmt.Errorf("no POSTGRES_USER env variable set"), |
| 59 | }, |
| 60 | { |
| 61 | Description: "no pg user", |
| 62 | Setup: func() { |
| 63 | fullSetup() |
| 64 | os.Unsetenv("POSTGRES_USER") |
| 65 | }, |
| 66 | ExpectedErr: fmt.Errorf("no POSTGRES_USER env variable set"), |
| 67 | }, |
| 68 | { |
| 69 | Description: "no pg password", |
| 70 | Setup: func() { |
nothing calls this directly
no test coverage detected