forked from cloudhut/connect-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
put_validate_connector_config_test.go
108 lines (93 loc) · 3.96 KB
/
put_validate_connector_config_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
package connect
import (
"context"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
// TestPutValidateConnectorConfigInvalidConfig tests the response of an invalid config.
func TestPutValidateConnectorConfigValidConfig(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
validateConnectorConfigOptions := ValidateConnectorConfigOptions{
Config: map[string]interface{}{"connector.class": "com.github.cloudhut.kowl.RegisteredConnector", "name": "connectorName"},
}
responseBody := `
{
"name": "com.github.cloudhut.kowl.RegisteredConnector",
"error_count": 0,
"groups": [],
"configs": []
}`
httpmock.RegisterResponder("PUT", baseURL+"/connector-plugins/registeredConnector/config/validate", newJsonStringResponder(http.StatusOK, responseBody))
validationResult, err := c.PutValidateConnectorConfig(context.Background(), "registeredConnector", validateConnectorConfigOptions)
assert.NoError(t, err)
assert.Equal(t, 0, validationResult.ErrorCount)
assert.Equal(t, []string{}, validationResult.Groups)
}
// TestPutValidateConnectorConfigInvalidConfig tests the response of an invalid config.
func TestPutValidateConnectorConfigInvalidConfig(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
validateConnectorConfigOptions := ValidateConnectorConfigOptions{
Config: map[string]interface{}{"connector.class": "com.github.cloudhut.kowl.RegisteredConnector"},
}
responseBody := `
{
"name": "com.github.cloudhut.kowl.RegisteredConnector",
"error_count": 1,
"groups": [
"Common"
],
"configs": [
{
"definition": {
"name": "name",
"type": "STRING",
"required": true,
"default_value": null,
"importance": "HIGH",
"documentation": "Globally unique name to use for this connector.",
"group": "Common",
"width": "MEDIUM",
"display_name": "Connector name",
"dependents": [],
"order": 1
},
"value": {
"name": "name",
"value": null,
"recommended_values": [],
"errors": [
"Missing required configuration \"name\" which has no default value."
],
"visible": true
}
}
]
}`
httpmock.RegisterResponder("PUT", baseURL+"/connector-plugins/registeredConnector/config/validate", newJsonStringResponder(http.StatusOK, responseBody))
validationResult, err := c.PutValidateConnectorConfig(context.Background(), "registeredConnector", validateConnectorConfigOptions)
assert.NoError(t, err)
assert.Equal(t, 1, validationResult.ErrorCount)
assert.Equal(t, []string{"Common"}, validationResult.Groups)
}
// TestPutValidateConnectorConfigInvalidConfig tests the response of a non-exising connect, i.e. an error and a default response.
func TestPutValidateConnectorConfigConnectorNotFound(t *testing.T) {
baseURL := "https://fake.api"
c := NewClient(WithHost(baseURL))
httpmock.ActivateNonDefault(c.client.GetClient())
defer httpmock.DeactivateAndReset()
validateConnectorConfigOptions := ValidateConnectorConfigOptions{
Config: map[string]interface{}{"connector.class": "com.github.cloudhut.kowl.RegisteredConnector", "name": "connectorName"},
}
httpmock.RegisterResponder("PUT", baseURL+"/connector-plugins/registeredConnector/config/validate", newJsonStringResponder(http.StatusNotFound, `notFound`))
validationResult, err := c.PutValidateConnectorConfig(context.Background(), "registeredConnector", validateConnectorConfigOptions)
assert.Error(t, err)
assert.Equal(t, ConnectorValidationResult{}, validationResult)
}