forked from theartofdevel/logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalias_test.go
79 lines (64 loc) · 2.05 KB
/
alias_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package logging
import (
"errors"
"testing"
"time"
)
func TestFloat32Attr(t *testing.T) {
key := "testKey"
val := float32(123.456)
attr := Float32Attr(key, val)
// Checking if the attribute correctly converts float32 to float64
if attr.Key != key || attr.Value.Float64() != float64(val) {
t.Errorf("Float32Attr() = %v, want %v", attr, Float64Attr(key, float64(val)))
}
}
func TestStringAttr(t *testing.T) {
key := "testKey"
val := "testValue"
attr := StringAttr(key, val)
if attr.Key != key || attr.Value.String() != val {
t.Errorf("key = %v, want %v", attr, StringAttr(key, val))
}
}
func TestErrAttr(t *testing.T) {
err := errors.New("test error")
attr := ErrAttr(err)
if attr.Key != "error" || attr.Value.String() != err.Error() {
t.Errorf("ErrAttr() = %v, want %v", attr, StringAttr("error", err.Error()))
}
}
func TestUInt32Attr(t *testing.T) {
key := "testKey"
val := uint32(123456789)
attr := UInt32Attr(key, val)
// The expected behavior is that UInt32Attr converts the uint32 to an int.
// We need to verify that this conversion is correct.
expectedValue := int(val)
if attr.Key != key || int(attr.Value.Int64()) != expectedValue {
t.Errorf("UInt32Attr() = {Key: %s, Value: %v}, want {Key: %s, Value: %v}",
attr.Key, attr.Value, key, expectedValue)
}
}
func TestInt32Attr(t *testing.T) {
key := "testKey"
val := int32(12345)
attr := Int32Attr(key, val)
// Verify that the attribute has the correct key and value
expectedValue := int(val)
if attr.Key != key || int(attr.Value.Int64()) != expectedValue {
t.Errorf("Int32Attr() = {Key: %s, Value: %v}, want {Key: %s, Value: %v}",
attr.Key, attr.Value, key, expectedValue)
}
}
func TestTimeAttr(t *testing.T) {
key := "timestamp"
val := time.Now()
attr := TimeAttr(key, val)
// Verify that the attribute has the correct key and the time in string format
expectedValue := val.String()
if attr.Key != key || attr.Value.String() != expectedValue {
t.Errorf("TimeAttr() = {Key: %s, Value: %v}, want {Key: %s, Value: %v}",
attr.Key, attr.Value, key, expectedValue)
}
}