| 1 |
// Licensed under the MIT license, see LICENSE file for details. |
| 2 |
|
| 3 |
//go:build go1.14 |
| 4 |
// +build go1.14 |
| 5 |
|
| 6 |
package quicktest_test |
| 7 |
|
| 8 |
import ( |
| 9 |
"os" |
| 10 |
"testing" |
| 11 |
|
| 12 |
qt "github.com/frankban/quicktest" |
| 13 |
) |
| 14 |
|
| 15 |
func TestPatchSetInt(t *testing.T) { |
| 16 |
i := 99 |
| 17 |
t.Run("subtest", func(t *testing.T) { |
| 18 |
qt.Patch(t, &i, 77) |
| 19 |
qt.Assert(t, i, qt.Equals, 77) |
| 20 |
}) |
| 21 |
qt.Assert(t, i, qt.Equals, 99) |
| 22 |
} |
| 23 |
|
| 24 |
func TestSetenv(t *testing.T) { |
| 25 |
const envName = "SOME_VAR" |
| 26 |
os.Setenv(envName, "initial") |
| 27 |
t.Run("subtest", func(t *testing.T) { |
| 28 |
qt.Setenv(t, envName, "a new value") |
| 29 |
qt.Check(t, os.Getenv(envName), qt.Equals, "a new value") |
| 30 |
}) |
| 31 |
qt.Check(t, os.Getenv(envName), qt.Equals, "initial") |
| 32 |
} |
| 33 |
|
| 34 |
func TestUnsetenv(t *testing.T) { |
| 35 |
const envName = "SOME_VAR" |
| 36 |
os.Setenv(envName, "initial") |
| 37 |
t.Run("subtest", func(t *testing.T) { |
| 38 |
qt.Unsetenv(t, envName) |
| 39 |
_, ok := os.LookupEnv(envName) |
| 40 |
qt.Assert(t, ok, qt.IsFalse) |
| 41 |
}) |
| 42 |
qt.Check(t, os.Getenv(envName), qt.Equals, "initial") |
| 43 |
} |