-
Notifications
You must be signed in to change notification settings - Fork 0
/
databricks_service_test.go
120 lines (112 loc) · 3.69 KB
/
databricks_service_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
package smile_databricks_gateway
import (
"reflect"
"testing"
)
func TestDatabricksService(t *testing.T) {
databricksService, close, err := NewDatabricksService(TestConfig.DBToken, TestConfig.DBTokenComment, TestConfig.DBHostname, TestConfig.DBHttpPath, TestConfig.SMILESchema, TestConfig.RequestTable, TestConfig.SampleTable, TestConfig.SlackURL, TestConfig.DBPort)
if err != nil {
t.Fatalf("databricks service cannot be created: %q", err)
}
defer close()
t.Run("inserting request to databricks", func(t *testing.T) {
wantRequest, err := UnmarshalT[SmileRequest]([]byte(RequestJSON))
if err != nil {
t.Fatalf("cannot unmarshal request: %q", err)
}
err = databricksService.InsertRequest(wantRequest)
if err != nil {
t.Error(err)
}
gotRequest, err := databricksService.GetRequest(wantRequest.IgoRequestID)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(gotRequest, wantRequest) {
t.Errorf("got %v want %v", gotRequest, wantRequest)
}
err = databricksService.RemoveRequest("IGO_TEST_REQUEST")
if err != nil {
t.Fatalf("error encountered removing request: %q", err)
}
})
t.Run("updating request in databricks", func(t *testing.T) {
insertedRequest, err := UnmarshalT[SmileRequest]([]byte(RequestJSON))
if err != nil {
t.Fatalf("cannot unmarshal request: %q", err)
}
err = databricksService.InsertRequest(insertedRequest)
if err != nil {
t.Error(err)
}
updatedRequest, err := UnmarshalT[SmileRequest]([]byte(RequestJSON))
if err != nil {
t.Fatalf("cannot unmarshal request: %q", err)
}
updatedRequest.LabHeadName = "homer simpson"
err = databricksService.UpdateRequest(updatedRequest)
if err != nil {
t.Error(err)
}
gotRequest, err := databricksService.GetRequest(updatedRequest.IgoRequestID)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(gotRequest, updatedRequest) {
t.Errorf("got %v want %v", gotRequest, updatedRequest)
}
err = databricksService.RemoveRequest("IGO_TEST_REQUEST")
if err != nil {
t.Fatalf("error encountered removing request: %q", err)
}
})
t.Run("inserting sample to databricks", func(t *testing.T) {
wantRequest, err := UnmarshalT[SmileRequest]([]byte(RequestJSON))
if err != nil {
t.Fatalf("cannot unmarshal request: %q", err)
}
err = databricksService.InsertSamples(wantRequest.IgoRequestID, wantRequest.Samples)
if err != nil {
t.Error(err)
}
wantSample := wantRequest.Samples[0]
gotSample, err := databricksService.GetSample(wantRequest.IgoRequestID, wantSample.SampleName)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(gotSample, wantSample) {
t.Errorf("got %v want %v", gotSample, wantSample)
}
err = databricksService.RemoveSamples("IGO_TEST_REQUEST")
if err != nil {
t.Fatalf("error encountered removing sample: %q", err)
}
})
t.Run("updating sample to databricks", func(t *testing.T) {
wantRequest, err := UnmarshalT[SmileRequest]([]byte(RequestJSON))
if err != nil {
t.Fatalf("cannot unmarshal request: %q", err)
}
err = databricksService.InsertSamples(wantRequest.IgoRequestID, wantRequest.Samples)
if err != nil {
t.Error(err)
}
updatedSample := wantRequest.Samples[0]
updatedSample.CmoSampleName = "brooklyn bonnies"
err = databricksService.UpdateSample(wantRequest.IgoRequestID, updatedSample)
if err != nil {
t.Error(err)
}
gotSample, err := databricksService.GetSample(wantRequest.IgoRequestID, updatedSample.SampleName)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(gotSample, updatedSample) {
t.Errorf("got %v want %v", gotSample, updatedSample)
}
err = databricksService.RemoveSamples("IGO_TEST_REQUEST")
if err != nil {
t.Fatalf("error encountered removing sample: %q", err)
}
})
}