-
Notifications
You must be signed in to change notification settings - Fork 8
/
distribution_test.go
79 lines (73 loc) · 2.12 KB
/
distribution_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
package opendota
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDistributionService_Distributions(t *testing.T) {
httpClient, mux, server := testServer()
defer server.Close()
mux.HandleFunc("/api/distributions", func(w http.ResponseWriter, r *http.Request) {
assertMethod(t, "GET", r)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"mmr":{"command":"SELECT","rowCount":98,"oid":null,"rows":[{"bin":0,"bin_name":0,"count":9786,"cumulative_sum":9786}],"fields":[{"name":"bin","tableID":0,"columnID":0,"dataTypeID":23,"dataTypeSize":4,"dataTypeModifier":-1,"format":"text"}],"rowAsArray":false,"sum":{"count":2444278}},"country_mmr":{"command":"SELECT","rowCount":255,"oid":null,"rows":[{"loccountrycode":"AN","count":1,"avg":"4113","common":"AN"}],"fields":[{"name":"loccountrycode","tableID":16405,"columnID":12,"dataTypeID":1043,"dataTypeSize":-1,"dataTypeModifier":6,"format":"text"}],"rowAsArray":false}}`)
})
expected := Distribution{
Mmr: Mmr{
Command: "SELECT",
RowCount: 98,
Rows: []MmrRow{
{
Bin: 0,
BinName: 0,
Count: 9786,
CumulativeSum: 9786,
},
},
Fields: []Field{
{
Name: "bin",
TableID: 0,
ColumnID: 0,
DataTypeID: 23,
DataTypeSize: 4,
DataTypeModifier: -1,
Format: "text",
},
},
RowAsArray: false,
Sum: Sum{
Count: 2444278,
},
},
CountryMmr: CountryMmr{
Command: "SELECT",
RowCount: 255,
Rows: []CountryMmrRow{
{
Loccountrycode: "AN",
Count: 1,
Avg: "4113",
Common: "AN",
},
},
Fields: []Field{
{
Name: "loccountrycode",
TableID: 16405,
ColumnID: 12,
DataTypeID: 1043,
DataTypeSize: -1,
DataTypeModifier: 6,
Format: "text",
},
},
RowAsArray: false,
},
}
client := NewClient(httpClient)
distributions, _, err := client.DistributionService.Distributions()
assert.Nil(t, err)
assert.Equal(t, expected, distributions)
}