@@ -86,66 +86,66 @@ func (s *FunctionalSuite) TestSemanticVersionColumnDiscard(c *C) {
86
86
}
87
87
}
88
88
89
- func TestEnvironmentSettingWithSecretsFiles (t * testing.T ) {
89
+ // test read username and password from file
90
+ func (s * FunctionalSuite ) TestEnvironmentSettingWithSecretsFiles (c * C ) {
90
91
91
92
err := os .Setenv ("DATA_SOURCE_USER_FILE" , "./tests/username_file" )
92
- if err != nil {
93
- t .Errorf ("DATA_SOURCE_USER_FILE could not be set" )
94
- }
93
+ c .Assert (err , IsNil )
94
+ defer UnsetEnvironment (c , "DATA_SOURCE_USER_FILE" )
95
95
96
96
err = os .Setenv ("DATA_SOURCE_PASS_FILE" , "./tests/userpass_file" )
97
- if err != nil {
98
- t .Errorf ("DATA_SOURCE_PASS_FILE could not be set" )
99
- }
97
+ c .Assert (err , IsNil )
98
+ defer UnsetEnvironment (c , "DATA_SOURCE_PASS_FILE" )
100
99
101
100
err = os .Setenv ("DATA_SOURCE_URI" , "localhost:5432/?sslmode=disable" )
102
- if err != nil {
103
- t .Errorf ("DATA_SOURCE_URI could not be set" )
104
- }
101
+ c .Assert (err , IsNil )
102
+ defer UnsetEnvironment (c , "DATA_SOURCE_URI" )
105
103
106
104
var expected = "postgresql://custom_username:custom_password@localhost:5432/?sslmode=disable"
107
105
108
106
dsn := getDataSource ()
109
107
if dsn != expected {
110
- t .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , expected )
108
+ c .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , expected )
111
109
}
112
110
}
113
111
114
- func TestEnvironmentSettingWithDns (t * testing.T ) {
112
+ // test read DATA_SOURCE_NAME from environment
113
+ func (s * FunctionalSuite ) TestEnvironmentSettingWithDns (c * C ) {
115
114
116
115
envDsn := "postgresql://user:password@localhost:5432/?sslmode=enabled"
117
116
err := os .Setenv ("DATA_SOURCE_NAME" , envDsn )
118
- if err != nil {
119
- t .Errorf ("DATA_SOURCE_NAME could not be set" )
120
- }
117
+ c .Assert (err , IsNil )
118
+ defer UnsetEnvironment (c , "DATA_SOURCE_NAME" )
121
119
122
120
dsn := getDataSource ()
123
121
if dsn != envDsn {
124
- t .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , envDsn )
122
+ c .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , envDsn )
125
123
}
126
124
}
127
125
128
- // test DATA_SOURCE_NAME is used even if username and password environment wariables are set
129
- func TestEnvironmentSettingWithDnsAndSecrets (t * testing. T ) {
126
+ // test DATA_SOURCE_NAME is used even if username and password environment variables are set
127
+ func ( s * FunctionalSuite ) TestEnvironmentSettingWithDnsAndSecrets (c * C ) {
130
128
131
129
envDsn := "postgresql://userDsn:passwordDsn@localhost:55432/?sslmode=disabled"
132
130
err := os .Setenv ("DATA_SOURCE_NAME" , envDsn )
133
- if err != nil {
134
- t .Errorf ("DATA_SOURCE_NAME could not be set" )
135
- }
131
+ c .Assert (err , IsNil )
132
+ defer UnsetEnvironment (c , "DATA_SOURCE_NAME" )
136
133
137
134
err = os .Setenv ("DATA_SOURCE_USER_FILE" , "./tests/username_file" )
138
- if err != nil {
139
- t .Errorf ("DATA_SOURCE_USER_FILE could not be set" )
140
- }
135
+ c .Assert (err , IsNil )
136
+ defer UnsetEnvironment (c , "DATA_SOURCE_USER_FILE" )
141
137
142
138
err = os .Setenv ("DATA_SOURCE_PASS" , "envUserPass" )
143
- if err != nil {
144
- t .Errorf ("DATA_SOURCE_PASS could not be set" )
145
- }
139
+ c .Assert (err , IsNil )
140
+ defer UnsetEnvironment (c , "DATA_SOURCE_PASS" )
146
141
147
142
dsn := getDataSource ()
148
143
if dsn != envDsn {
149
- t .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , envDsn )
144
+ c .Errorf ("Expected Username to be read from file. Found=%v, expected=%v" , dsn , envDsn )
150
145
}
151
146
}
147
+
148
+ func UnsetEnvironment (c * C , d string ) {
149
+ err := os .Unsetenv (d )
150
+ c .Assert (err , IsNil )
151
+ }
0 commit comments