This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
annotation_test.go
66 lines (54 loc) · 1.55 KB
/
annotation_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
package simplejson_test
import (
"encoding/json"
"github.com/clambin/simplejson/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func TestAnnotation_MarshalJSON(t *testing.T) {
ann := simplejson.Annotation{
Time: time.Date(2022, time.January, 23, 0, 0, 0, 0, time.UTC),
Title: "foo",
Text: "bar",
Tags: []string{"A", "B"},
Request: simplejson.RequestDetails{
Name: "snafu",
Datasource: "datasource",
Enable: true,
Query: "A == 10",
},
}
body, err := json.Marshal(ann)
require.NoError(t, err)
gp := filepath.Join("testdata", strings.ToLower(t.Name()), "1.golden")
if *update {
t.Logf("updating golden file for %s", t.Name())
err = os.WriteFile(gp, body, 0644)
require.NoError(t, err, "failed to update golden file")
}
var golden []byte
golden, err = os.ReadFile(gp)
require.NoError(t, err)
assert.Equal(t, golden, body)
ann.TimeEnd = time.Date(2022, time.January, 23, 0, 0, 0, 0, time.UTC)
body, err = json.Marshal(ann)
require.NoError(t, err)
assert.Equal(t, golden, body)
ann.TimeEnd = time.Date(2022, time.January, 23, 1, 0, 0, 0, time.UTC)
body, err = json.Marshal(ann)
require.NoError(t, err)
gp = filepath.Join("testdata", strings.ToLower(t.Name()), "2.golden")
if *update {
t.Logf("updating golden file for %s", t.Name())
err = os.WriteFile(gp, body, 0644)
require.NoError(t, err, "failed to update golden file")
}
golden, err = os.ReadFile(gp)
require.NoError(t, err)
assert.Equal(t, golden, body)
}