-
Notifications
You must be signed in to change notification settings - Fork 2
/
labels_test.go
98 lines (76 loc) · 2.37 KB
/
labels_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 logentries_goclient
import (
"fmt"
"github.com/dikhan/http_goclient/testutils"
"github.com/stretchr/testify/assert"
"net/http"
"reflect"
"testing"
)
func TestLabels_GetLabels(t *testing.T) {
expectedLabels := []Label{
{
Id: "label-uuid",
Name: "Login Failure",
Reserved: false,
Color: "007afb",
SN: 1056,
},
}
requestMatcher := testutils.NewRequestMatcher(http.MethodGet, "/management/labels", nil, http.StatusOK, &labelsCollection{expectedLabels})
labels := getLabelsClient(requestMatcher)
returnedLabels, err := labels.GetLabels()
assert.Nil(t, err)
assert.True(t, reflect.DeepEqual(expectedLabels, returnedLabels))
}
func TestTags_GetLabel(t *testing.T) {
expectedLabel := Label{
Id: "label-uuid",
Name: "Login Failure",
Reserved: false,
Color: "007afb",
SN: 1056,
}
url := fmt.Sprintf("/management/labels/%s", expectedLabel.Id)
requestMatcher := testutils.NewRequestMatcher(http.MethodGet, url, nil, http.StatusOK, &getLabel{expectedLabel})
labels := getLabelsClient(requestMatcher)
returnedLabel, err := labels.GetLabel(expectedLabel.Id)
assert.Nil(t, err)
assert.EqualValues(t, expectedLabel, returnedLabel)
}
func TestTags_GetLabelErrorsIfTagIdIsEmpty(t *testing.T) {
labels := Labels{nil}
_, err := labels.GetLabel("")
assert.NotNil(t, err)
assert.Error(t, err, "labelId input parameter is mandatory")
}
func getLabelsClient(requestMatcher testutils.TestRequestMatcher) Labels {
c := getTestClient(requestMatcher)
return newLabels(c)
}
func TestLabels_DeleteLabel(t *testing.T) {
labelId := "log-set-uuid"
url := fmt.Sprintf("/management/labels/%s", labelId)
requestMatcher := testutils.NewRequestMatcher(http.MethodDelete, url, nil, http.StatusNoContent, nil)
label := getLabelsClient(requestMatcher)
err := label.DeleteLabel(labelId)
assert.Nil(t, err)
}
func TestLabels_PostLabel(t *testing.T) {
p := PostLabel{
Name: "My Label",
Color: "ff0000",
}
expectedLabel := Label{
Id: "label-uuid",
Name: p.Name,
Color: p.Color,
Reserved: false,
SN: 1021,
}
requestMatcher := testutils.NewRequestMatcher(http.MethodPost, "/management/labels", &postLabel{p}, http.StatusCreated, &getLabel{expectedLabel})
log := getLabelsClient(requestMatcher)
returnedLabel, err := log.PostLabel(p)
assert.Nil(t, err)
assert.EqualValues(t, expectedLabel, returnedLabel)
}