Skip to content

Commit 148148d

Browse files
committed
metric_test.go: add TestBOOL_MarshalText and TestBOOL_UnmarshalText.
1 parent 44b6ddd commit 148148d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

metric/metric_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package metric
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestBOOL_MarshalText(t *testing.T) {
10+
t.Run("true", func(t *testing.T) {
11+
TRUE := BOOL(1)
12+
output, err := TRUE.MarshalText()
13+
require.NoError(t, err)
14+
require.Equal(t, output, []byte("true"))
15+
})
16+
17+
t.Run("false", func(t *testing.T) {
18+
FALSE := BOOL(0)
19+
output, err := FALSE.MarshalText()
20+
require.NoError(t, err)
21+
require.Equal(t, output, []byte("false"))
22+
})
23+
}
24+
25+
func TestBOOL_UnmarshalText(t *testing.T) {
26+
t.Run("true", func(t *testing.T) {
27+
var b BOOL
28+
29+
err := b.UnmarshalText([]byte("true"))
30+
require.NoError(t, err)
31+
require.Equal(t, BOOL(1), b)
32+
33+
err = b.UnmarshalText([]byte("True"))
34+
require.NoError(t, err)
35+
require.Equal(t, BOOL(1), b)
36+
})
37+
38+
t.Run("false", func(t *testing.T) {
39+
var b BOOL
40+
41+
err := b.UnmarshalText([]byte("false"))
42+
require.NoError(t, err)
43+
require.Equal(t, BOOL(0), b)
44+
45+
err = b.UnmarshalText([]byte("False"))
46+
require.NoError(t, err)
47+
require.Equal(t, BOOL(0), b)
48+
})
49+
50+
t.Run("invalid", func(t *testing.T) {
51+
var b BOOL
52+
53+
err := b.UnmarshalText([]byte("invalid"))
54+
require.EqualError(t, err, "invalid BOOL value")
55+
})
56+
}

0 commit comments

Comments
 (0)