-
Notifications
You must be signed in to change notification settings - Fork 8
/
explorer_test.go
53 lines (47 loc) · 1.58 KB
/
explorer_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
package opendota
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExplorerService_Explorer(t *testing.T) {
httpClient, mux, server := testServer()
defer server.Close()
mux.HandleFunc("/api/explorer", func(w http.ResponseWriter, r *http.Request) {
assertMethod(t, "GET", r)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"command":"SELECT","rowCount":115,"oid":null,"rows":[{"id":44,"name":"npc_dota_hero_phantom_assassin","localized_name":"Phantom Assassin","primary_attr":"agi","attack_type":"Melee","roles":["Carry","Escape"],"legs":2}],"fields":[{"name":"id","tableID":929536173,"columnID":1,"dataTypeID":23,"dataTypeSize":4,"dataTypeModifier":-1,"format":"text"}],"rowAsArray":false,"err":null}`)
})
expected := QueryResult{
Command: "SELECT",
RowCount: 115,
Rows: []map[string]interface{}{
{
"id": float64(44),
"name": "npc_dota_hero_phantom_assassin",
"localized_name": "Phantom Assassin",
"primary_attr": "agi",
"attack_type": "Melee",
"roles": []interface{}{"Carry", "Escape"},
"legs": float64(2),
},
},
Fields: []Field{
{
Name: "id",
TableID: 929536173,
ColumnID: 1,
DataTypeID: 23,
DataTypeSize: 4,
DataTypeModifier: -1,
Format: "text",
},
},
RowAsArray: false,
}
client := NewClient(httpClient)
queryresult, _, err := client.ExplorerService.Explore("SELECT%20*%20FROM%20public.heroes")
assert.Nil(t, err)
assert.Equal(t, expected, queryresult)
}