| 1 |
// Licensed under the MIT license, see LICENSE file for details. |
| 2 |
|
| 3 |
//go:build !go1.17 |
| 4 |
// +build !go1.17 |
| 5 |
|
| 6 |
package quicktest_test |
| 7 |
|
| 8 |
import ( |
| 9 |
"os" |
| 10 |
"testing" |
| 11 |
|
| 12 |
qt "github.com/frankban/quicktest" |
| 13 |
) |
| 14 |
|
| 15 |
const envName = "SOME_VAR" |
| 16 |
|
| 17 |
func TestCSetenv(t *testing.T) { |
| 18 |
c := qt.New(t) |
| 19 |
os.Setenv(envName, "initial") |
| 20 |
testCleanup(t, func(c *qt.C) { |
| 21 |
c.Setenv(envName, "new value") |
| 22 |
c.Check(os.Getenv(envName), qt.Equals, "new value") |
| 23 |
}) |
| 24 |
c.Check(os.Getenv(envName), qt.Equals, "initial") |
| 25 |
} |
| 26 |
|
| 27 |
func TestCSetenvWithUnsetVariable(t *testing.T) { |
| 28 |
c := qt.New(t) |
| 29 |
os.Unsetenv(envName) |
| 30 |
testCleanup(t, func(c *qt.C) { |
| 31 |
c.Setenv(envName, "new value") |
| 32 |
c.Check(os.Getenv(envName), qt.Equals, "new value") |
| 33 |
}) |
| 34 |
_, ok := os.LookupEnv(envName) |
| 35 |
c.Assert(ok, qt.IsFalse) |
| 36 |
} |