-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathquery_annotation_test.go
98 lines (75 loc) · 2 KB
/
query_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package honeycombio
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestQueryAnnotations(t *testing.T) {
ctx := context.Background()
c := newTestClient(t)
dataset := testDataset(t)
var queryAnnotation *QueryAnnotation
var err error
query, err := c.Queries.Create(ctx, dataset, &QuerySpec{
Calculations: []CalculationSpec{
{
Op: "COUNT",
},
},
})
if err != nil {
t.Fatal(err)
}
t.Run("Create", func(t *testing.T) {
data := &QueryAnnotation{
Name: "Query created by a test",
Description: "This derived column is created by a test",
QueryID: *query.ID,
}
queryAnnotation, err = c.QueryAnnotations.Create(ctx, dataset, data)
if err != nil {
t.Fatal(err)
}
data.ID = queryAnnotation.ID
assert.Equal(t, data, queryAnnotation)
})
t.Run("List", func(t *testing.T) {
queryAnnotations, err := c.QueryAnnotations.List(ctx, dataset)
if err != nil {
t.Fatal(err)
}
assert.Contains(t, queryAnnotations, *queryAnnotation, "could not find QueryAnnotation with List")
})
t.Run("Get", func(t *testing.T) {
result, err := c.QueryAnnotations.Get(ctx, dataset, queryAnnotation.ID)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, *queryAnnotation, *result)
})
t.Run("Update", func(t *testing.T) {
// change all the fields to test
data := &QueryAnnotation{
ID: queryAnnotation.ID,
Name: "This is a new name for the query created by a test",
Description: "This is a new description",
QueryID: *query.ID,
}
queryAnnotation, err = c.QueryAnnotations.Update(ctx, dataset, data)
if err != nil {
t.Fatal(err)
}
data.ID = queryAnnotation.ID
assert.Equal(t, data, queryAnnotation)
})
t.Run("Delete", func(t *testing.T) {
err = c.QueryAnnotations.Delete(ctx, dataset, queryAnnotation.ID)
if err != nil {
t.Fatal(err)
}
})
t.Run("Get_notFound", func(t *testing.T) {
_, err := c.QueryAnnotations.Get(ctx, dataset, queryAnnotation.ID)
assert.Equal(t, ErrNotFound, err)
})
}