-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_test.go
More file actions
86 lines (73 loc) · 2.55 KB
/
push_test.go
File metadata and controls
86 lines (73 loc) · 2.55 KB
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
package Warp10Exporter
import (
"errors"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestGTSPush(t *testing.T) {
internalServerError := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}))
defer internalServerError.Close()
singleGTSValidatorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
if string(body) != singleGTSSingleDatapointString {
t.Errorf("Expected '%v', got '%v'", singleGTSSingleDatapointString, string(body))
}
}))
defer singleGTSValidatorServer.Close()
err := singleGTSSingleDatapoint.Push(internalServerError.URL, "abcd")
if !strings.Contains(err.Error(), "Internal Server Error") {
t.Errorf("Expected 'Internal Server Error', got '%v'", err)
}
err = singleGTSSingleDatapoint.Push(singleGTSValidatorServer.URL, "abcd")
if err != nil {
t.Errorf("Expected 'nil', got '%v'", err)
}
err = singleGTSSingleDatapoint.Push("256.256.256.256:9091", "abcd")
expected := errors.New("parse 256.256.256.256:9091/api/v0/update: first path segment in URL cannot contain colon")
if err.Error() != expected.Error() {
t.Errorf("Expected '%v', got '%v'", expected, err)
}
err = singleGTSSingleDatapoint.Push("", "abcd")
expected = errors.New("Post /api/v0/update: unsupported protocol scheme \"\"")
if err.Error() != expected.Error() {
t.Errorf("Expected '%v', got '%v'", expected, err)
}
gts := NewGTS("dsa")
gts.Push("", "abcd")
}
func TestBatchPush(t *testing.T) {
batch := NewBatch()
gts := NewGTS("test").WithLabels(labels)
batch.Register(gts)
gts.AddDatapoint(ts, 42)
singleGTSValidatorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
if string(body) != singleGTSSingleDatapointString {
t.Errorf("Expected '%v', got '%v'", singleGTSSingleDatapointString, string(body))
}
}))
defer singleGTSValidatorServer.Close()
err := batch.Push(singleGTSValidatorServer.URL, "abcd")
if err != nil {
t.Errorf("Expected '%v', got '%v'", nil, err)
}
}
func TestEmptyBatchPush(t *testing.T) {
batch := NewBatch()
err := batch.Push("", "abcd")
if err != ErrEmptyBatch {
t.Errorf("Expected '%v', got '%v'", ErrEmptyBatch, err)
}
}
func TestEmptyGTSPush(t *testing.T) {
gts := NewGTS("test").WithLabels(labels)
err := gts.Push("", "abcd")
if err != ErrEmptyGTS {
t.Errorf("Expected '%v', got '%v'", ErrEmptyGTS, err)
}
}