-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfunctions_test.go
143 lines (140 loc) · 3.45 KB
/
functions_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Package cisearch provides GCS indexer functions
package cisearch
import (
"context"
"reflect"
"testing"
)
func TestIndexJobs(t *testing.T) {
tests := []struct {
name string
e GCSEvent
wantErr bool
}{
// TODO: make the actual write a no-op in tests
// {
// e: GCSEvent{
// Bucket: "origin-ci-test",
// Name: "logs/release-openshift-origin-installer-e2e-gcp-upgrade-4.8/1366716541889941504/artifacts/e2e-gcp-upgrade/gather-extra/artifacts/metrics/job_metrics.json",
// },
// },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := IndexJobs(context.TODO(), tt.e); (err != nil) != tt.wantErr {
t.Errorf("IndexJobs() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestPrometheusValue_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
data []byte
wantErr bool
initial *PrometheusValue
expect *PrometheusValue
}{
{
data: []byte(`null`),
initial: &PrometheusValue{},
expect: &PrometheusValue{},
},
{
data: []byte(`null`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Value: "test"},
},
{
data: []byte(`null`),
initial: nil,
expect: nil,
},
{
data: []byte(`[]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Value: "test"},
wantErr: true,
},
{
data: []byte(`[1]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, 2]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1,`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1,]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, `),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, ]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, "]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, ""]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, " 1 "]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "test"},
wantErr: true,
},
{
data: []byte(`[1, "1"]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "1"},
},
{
data: []byte(`[1, "1.1"]`),
initial: &PrometheusValue{Value: "test"},
expect: &PrometheusValue{Timestamp: 1, Value: "1.1"},
},
}
for _, tt := range tests {
n := tt.name
if len(n) == 0 {
n = string(tt.data)
}
t.Run(n, func(t *testing.T) {
err := tt.initial.UnmarshalJSON(tt.data)
if (err != nil) != tt.wantErr {
t.Errorf("PrometheusValue.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
t.Logf("%v", err)
if !reflect.DeepEqual(tt.expect, tt.initial) {
t.Errorf("Unexpected output value: %#v", tt.initial)
}
})
}
}