-
Notifications
You must be signed in to change notification settings - Fork 41
/
mock.go
102 lines (89 loc) · 2.44 KB
/
mock.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
package azkustoingest
import (
"context"
"github.com/Azure/azure-kusto-go/azkustodata"
"github.com/Azure/azure-kusto-go/azkustodata/errors"
"github.com/Azure/azure-kusto-go/azkustodata/query"
"github.com/Azure/azure-kusto-go/azkustodata/query/v1"
"github.com/Azure/azure-kusto-go/azkustodata/types"
"net/http"
)
type mockClient struct {
endpoint string
auth azkustodata.Authorization
onMgmt func(ctx context.Context, db string, query azkustodata.Statement, options ...azkustodata.QueryOption) (v1.Dataset, error)
}
func (m mockClient) Query(_ context.Context, _ string, _ azkustodata.Statement, _ ...azkustodata.QueryOption) (query.Dataset, error) {
panic("not implemented")
}
func (m mockClient) IterativeQuery(_ context.Context, _ string, _ azkustodata.Statement, _ ...azkustodata.QueryOption) (query.IterativeDataset, error) {
panic("not implemented")
}
func (m mockClient) ClientDetails() *azkustodata.ClientDetails {
return azkustodata.NewClientDetails("test", "test")
}
func (m mockClient) HttpClient() *http.Client {
return &http.Client{}
}
func (m mockClient) Close() error {
return nil
}
func (m mockClient) Auth() azkustodata.Authorization {
return m.auth
}
func (m mockClient) Endpoint() string {
return m.endpoint
}
func (m mockClient) Mgmt(ctx context.Context, db string, query azkustodata.Statement, options ...azkustodata.QueryOption) (v1.Dataset, error) {
if m.onMgmt != nil {
rows, err := m.onMgmt(ctx, db, query, options...)
if err != nil || rows != nil {
return rows, err
}
}
if query.String() == ".get kusto identity token" {
return v1.NewDataset(ctx, errors.OpMgmt, v1.V1{
Tables: []v1.RawTable{
{
TableName: "Table",
Columns: []v1.RawColumn{
{
ColumnName: "AuthorizationContext",
ColumnType: string(types.String),
},
},
Rows: []v1.RawRow{
{
Row: []interface{}{"mock"},
Errors: nil,
},
},
},
}})
}
return v1.NewDataset(ctx, errors.OpMgmt, v1.V1{
Tables: []v1.RawTable{
{
TableName: "Table",
Columns: []v1.RawColumn{
{
ColumnName: "ResourceTypeName",
ColumnType: string(types.String),
},
{
ColumnName: "StorageRoot",
ColumnType: string(types.String),
},
},
Rows: []v1.RawRow{},
},
}})
}
func newMockClient() mockClient {
return mockClient{
endpoint: "localhost",
auth: azkustodata.Authorization{
TokenProvider: &azkustodata.TokenProvider{},
},
}
}