forked from cloudhut/connect-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restart_connector_test.go
74 lines (65 loc) · 2.34 KB
/
restart_connector_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
package connect
import (
"context"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
// TestRestartConnectors tests the success case for restarting connectors in a connect cluster.
func TestRestartConnectors(t *testing.T) {
baseURL := "https://fake.api"
tests := []struct {
title string
url string
options RestartConnectorOptions
}{
{
title: "default",
url: baseURL + "/connectors/my-connector/restart",
options: RestartConnectorOptions{},
},
{
title: "includeTasks=false",
url: baseURL + "/connectors/my-connector/restart?includeTasks=false&onlyFailed=false",
options: RestartConnectorOptions{IncludeTasks: false},
},
{
title: "onlyFailed=false",
url: baseURL + "/connectors/my-connector/restart?includeTasks=false&onlyFailed=false",
options: RestartConnectorOptions{OnlyFailed: false},
},
{
title: "both false",
url: baseURL + "/connectors/my-connector/restart?includeTasks=false&onlyFailed=false",
options: RestartConnectorOptions{IncludeTasks: false, OnlyFailed: false},
},
{
title: "include tasks",
url: baseURL + "/connectors/my-connector/restart?includeTasks=true&onlyFailed=false",
options: RestartConnectorOptions{IncludeTasks: true},
},
{
title: "include only failed",
url: baseURL + "/connectors/my-connector/restart?includeTasks=false&onlyFailed=true",
options: RestartConnectorOptions{OnlyFailed: true},
},
{
title: "include both",
url: baseURL + "/connectors/my-connector/restart?includeTasks=true&onlyFailed=true",
options: RestartConnectorOptions{IncludeTasks: true, OnlyFailed: true},
},
}
for _, tt := range tests {
t.Run(tt.title, func(t *testing.T) {
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("POST", tt.url,
newJsonStringResponder(http.StatusOK,
`{"name": "my-connector","connector": {"state": "RUNNING","worker_id": "fakehost1:8083"},"tasks":[{"id": 0,"state": "RUNNING","worker_id": "fakehost2:8083"},{"id": 1,"state": "RESTARTING","worker_id": "fakehost3:8083"},{"id": 2,"state": "RESTARTING","worker_id": "fakehost1:8083"}]}`))
err := c.RestartConnector(context.Background(), "my-connector", tt.options)
assert.NoError(t, err)
})
}
}