-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils_test.go
53 lines (43 loc) · 1.07 KB
/
utils_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
package hutils
import (
"context"
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONMarshal(t *testing.T) {
symbol := "<" // "\u003c"
escape, err := json.Marshal(symbol)
if err != nil {
t.Error(err)
}
assert.Equal(t, len(string(escape)), 8)
noescape, err := JSONMarshal(symbol)
if err != nil {
t.Error(err)
}
assert.Equal(t, len(string(noescape)), 4)
}
func TestGetEnv(t *testing.T) {
value := GetEnv("key", "1")
assert.Equal(t, value, "1")
err := os.Setenv("key", "2")
assert.Equal(t, err, nil)
value = GetEnv("key", "")
assert.Equal(t, value, "2")
}
func TestNewUUID(t *testing.T) {
uid := NewUUID()
assert.Equal(t, len(uid), 32)
}
func TestNewApm(t *testing.T) {
span := NewApmSpan(context.Background(), "TestApm", "test")
assert.NotEqual(t, span, nil)
}
func TestNewZError(t *testing.T) {
err := NewZError(nil, "10086", "TestNewZError")
assert.Equal(t, "10086: TestNewZError", err.Error())
err = NewZError(nil, "10087", "TestNewZError", WithError(err))
assert.Equal(t, "10086: TestNewZError", err.Err.Error())
}