forked from rgalanakis/golangal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
golangal_test.go
55 lines (44 loc) · 1.27 KB
/
golangal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package golangal_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/rgalanakis/golangal"
"os"
"testing"
)
func TestGolangal(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "golangal package Suite")
}
var _ = Describe("EachTempDir and SuiteTempDir", func() {
tempdir := golangal.EachTempDir()
It("creates a temporary directory", func() {
Expect(tempdir()).To(HavePrefix(os.TempDir()))
})
})
var _ = Describe("Envvars", func() {
addEnvVar := golangal.EnvVars()
It("cleans up env vars (check before)", func() {
_, exists := os.LookupEnv("SOME_VAR")
Expect(exists).To(BeFalse())
})
It("sets the env var", func() {
addEnvVar("SOME_VAR", "X")
Expect(os.Getenv("SOME_VAR")).To(Equal("X"))
})
It("cleans up env vars (check after)", func() {
_, exists := os.LookupEnv("SOME_VAR")
Expect(exists).To(BeFalse())
})
var originalUserValue string
It("restores original values (check some var exists)", func() {
originalUserValue = os.Getenv("USER")
Expect(originalUserValue).ToNot(Equal(""))
})
It("restores original values (replace existing var)", func() {
addEnvVar("USER", "golangal-test-temp")
})
It("restores original values (check some var exists)", func() {
Expect(os.Getenv("USER")).To(Equal(originalUserValue))
})
})