Repository navigation
Expand file tree
/
Copy pathgenv_test.go
More file actions
87 lines (77 loc) · 1.99 KB
/
Copy pathgenv_test.go
File metadata and controls
87 lines (77 loc) · 1.99 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2017-2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package genv_test
import (
"os"
"testing"
"github.com/gogf/gf/os/genv"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/test/gtest"
"github.com/gogf/gf/util/gconv"
)
func Test_GEnv_All(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(os.Environ(), genv.All())
})
}
func Test_GEnv_Map(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST")
t.Assert(err, nil)
t.Assert(genv.Map()[key], "TEST")
})
}
func Test_GEnv_Get(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST")
t.Assert(err, nil)
t.AssertEQ(genv.Get(key), "TEST")
})
}
func Test_GEnv_Contains(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST")
t.Assert(err, nil)
t.AssertEQ(genv.Contains(key), true)
t.AssertEQ(genv.Contains("none"), false)
})
}
func Test_GEnv_Set(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value
err := genv.Set(key, "TEST")
t.Assert(err, nil)
t.AssertEQ(os.Getenv(key), "TEST")
})
}
func Test_GEnv_Build(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
s := genv.Build(map[string]string{
"k1": "v1",
"k2": "v2",
})
t.AssertIN("k1=v1", s)
t.AssertIN("k2=v2", s)
})
}
func Test_GEnv_Remove(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST")
t.Assert(err, nil)
err = genv.Remove(key)
t.Assert(err, nil)
t.AssertEQ(os.Getenv(key), "")
})
}