-
Notifications
You must be signed in to change notification settings - Fork 5
/
fromenv_test.go
34 lines (28 loc) · 954 Bytes
/
fromenv_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
package gofofa
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestFofaURLFromEnv(t *testing.T) {
defer func() {
os.Unsetenv("FOFA_CLIENT_URL")
os.Unsetenv("FOFA_SERVER")
os.Unsetenv("FOFA_EMAIL")
os.Unsetenv("FOFA_KEY")
}()
os.Setenv("FOFA_SERVER", "https://1.1.1.1")
os.Setenv("FOFA_EMAIL", "[email protected]")
os.Setenv("FOFA_KEY", "123456")
os.Unsetenv("FOFA_CLIENT_URL")
assert.Equal(t, "https://1.1.1.1/[email protected]&key=123456&version=v1", FofaURLFromEnv())
// 异常
os.Setenv("FOFA_CLIENT_URL", "\x7f")
assert.Equal(t, "", FofaURLFromEnv())
// 部分更新
os.Setenv("FOFA_CLIENT_URL", "https://2.2.2.2/[email protected]")
assert.Equal(t, "https://2.2.2.2/[email protected]&key=123456&version=v1", FofaURLFromEnv())
// 全更新
os.Setenv("FOFA_CLIENT_URL", "https://2.2.2.2/[email protected]&key=000000&version=v2")
assert.Equal(t, "https://2.2.2.2/[email protected]&key=000000&version=v2", FofaURLFromEnv())
}