Skip to content

Commit 454dd7a

Browse files
committed
Use t.Setenv in endtoend tests
t.Setenv restores the previous value when the test exits, which avoids leaking SQLC_DUMMY_VALUE and the per-example VET_TEST_* URIs into other tests in the same process. https://claude.ai/code/session_01RCzB2JR5Y5ScFDUmwcxGVZ
1 parent f70fa53 commit 454dd7a

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

internal/endtoend/endtoend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ type textContext struct {
201201
func TestReplay(t *testing.T) {
202202
// Ensure that this environment variable is always set to true when running
203203
// end-to-end tests
204-
os.Setenv("SQLC_DUMMY_VALUE", "true")
204+
t.Setenv("SQLC_DUMMY_VALUE", "true")
205205

206206
// t.Parallel()
207207
ctx := context.Background()

internal/endtoend/vet_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func TestExamplesVet(t *testing.T) {
6060
}
6161
if s, found := findSchema(t, filepath.Join(path, "mysql")); found {
6262
uri := local.MySQL(t, []string{s})
63-
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_MYSQL_%s", strings.ToUpper(tc)), uri)
63+
t.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_MYSQL_%s", strings.ToUpper(tc)), uri)
6464
}
6565
if s, found := findSchema(t, filepath.Join(path, "postgresql")); found {
6666
uri := local.PostgreSQL(t, []string{s})
67-
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_POSTGRES_%s", strings.ToUpper(tc)), uri)
67+
t.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_POSTGRES_%s", strings.ToUpper(tc)), uri)
6868
}
6969
}
7070

0 commit comments

Comments
 (0)