-
Notifications
You must be signed in to change notification settings - Fork 3
/
list_connectors_test.go
65 lines (51 loc) · 2.96 KB
/
list_connectors_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
package connect
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
)
// TestListConnectors tests the success case for listing all connectors in a connect cluster.
func TestListConnectors(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", baseURL+"/connectors", newJsonStringResponder(http.StatusOK, `["datagen-product"]`))
connectors, err := c.ListConnectors(context.Background())
assert.NoError(t, err)
assert.Equal(t, []string{"datagen-product"}, connectors)
}
// TestListConnectorsExpanded tests the success case for listing all connectors with expanded info (info and status)
// in a connect cluster.
func TestListConnectorsExpanded(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", baseURL+"/connectors?expand=info&expand=status", newJsonStringResponder(http.StatusOK, `{"datagen-product":{"info":{"name":"datagen-product","config":{"connector.class":"io.confluent.kafka.connect.datagen.DatagenConnector","quickstart":"product","tasks.max":"1","value.converter.schemas.enable":"false","name":"datagen-product","kafka.topic":"product","max.interval":"1000","iterations":"10000000"},"tasks":[{"connector":"datagen-product","task":0}],"type":"source"},"status":{"name":"datagen-product","connector":{"state":"RUNNING","worker_id":"connect:8083"},"tasks":[{"id":0,"state":"RUNNING","worker_id":"connect:8083"}],"type":"source"}}}`))
connectors, err := c.ListConnectorsExpanded(context.Background())
assert.NoError(t, err)
require.Len(t, connectors, 1)
mockConnector := connectors["datagen-product"]
require.NotNil(t, mockConnector)
assert.Equal(t, mockConnector.Info.Name, "datagen-product")
require.NotNil(t, mockConnector.Info.Config)
assert.Equal(t, mockConnector.Info.Config["connector.class"], "io.confluent.kafka.connect.datagen.DatagenConnector")
assert.Equal(t, mockConnector.Status.Name, "datagen-product")
assert.Equal(t, mockConnector.Status.Connector.State, "RUNNING")
}
// TestListConnectorsExpandedEmpty tests the success case for listing all connectors with expanded info (info and status)
// in a connect cluster. However in this specific case the response is an empty object because no connectors may be existent.
func TestListConnectorsExpandedEmpty(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", baseURL+"/connectors?expand=info&expand=status", newJsonStringResponder(http.StatusOK, `{}`))
connectors, err := c.ListConnectorsExpanded(context.Background())
assert.NoError(t, err)
assert.Len(t, connectors, 0)
}