-
Notifications
You must be signed in to change notification settings - Fork 18
/
mbeans_test.go
76 lines (68 loc) · 1.59 KB
/
mbeans_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
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"reflect"
"testing"
"time"
)
type solrVersionJSON struct {
version string
json io.Reader
}
var solrResponseDir = "utils/solr-responses"
func loadAllMbeans() ([]solrVersionJSON, error) {
mbeans := []solrVersionJSON{}
solrVersions, err := ioutil.ReadDir(solrResponseDir)
if err != nil {
return mbeans, fmt.Errorf("failed to list solr versions")
}
for _, sv := range solrVersions {
mbeansFile := path.Join(solrResponseDir, sv.Name(), "mbeans.json")
fi, err := os.Stat(mbeansFile)
if err != nil {
continue
}
file, err := os.Open(mbeansFile)
if err != nil {
return nil, fmt.Errorf("Failed to open file %s", fi.Name())
}
mbeans = append(mbeans, solrVersionJSON{sv.Name(), file})
}
return mbeans, nil
}
func Test_processMbeans(t *testing.T) {
type args struct {
e *Exporter
coreName string
data io.Reader
}
type test struct {
name string
args args
want []error
}
hc := http.Client{}
exporter := NewExporter("", time.Second, "", hc)
tests := []test{}
mbeans, err := loadAllMbeans()
if err != nil {
t.Errorf("enumerating solr versions: %v", err)
}
for _, mbean := range mbeans {
tests = append(tests, test{name: mbean.version, args: args{exporter, "gettingstarted", mbean.json}, want: []error{}})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := processMbeans(tt.args.e, tt.args.coreName, tt.args.data); !reflect.DeepEqual(got, tt.want) {
for _, err := range got {
t.Errorf("processMbeans() returned error: %v", err)
}
}
})
}
}