Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Sep 7, 2023
1 parent 8a0dbf2 commit 6dacbed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/plugin/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ func TestConnect(t *testing.T) {
ssl := getEnv("CLICKHOUSE_SSL", "false")
queryTimeoutNumber := 3600
queryTimeoutString := "3600"
path := "custom-path"
clickhouse := plugin.Clickhouse{}
t.Run("should not error when valid settings passed", func(t *testing.T) {
secure := map[string]string{}
secure["password"] = password
settings := backend.DataSourceInstanceSettings{JSONData: []byte(fmt.Sprintf(`{ "server": "%s", "port": %s, "username": "%s", "secure": %s, "queryTimeout": "%s"}`, host, port, username, ssl, queryTimeoutString)), DecryptedSecureJSONData: secure}
settings := backend.DataSourceInstanceSettings{JSONData: []byte(fmt.Sprintf(`{ "server": "%s", "port": %s, "path": "%s", "username": "%s", "secure": %s, "queryTimeout": "%s"}`, host, port, path, username, ssl, queryTimeoutString)), DecryptedSecureJSONData: secure}
_, err := clickhouse.Connect(settings, json.RawMessage{})
assert.Equal(t, nil, err)
})
Expand All @@ -147,11 +148,12 @@ func TestHTTPConnect(t *testing.T) {
username := getEnv("CLICKHOUSE_USERNAME", "default")
password := getEnv("CLICKHOUSE_PASSWORD", "")
ssl := getEnv("CLICKHOUSE_SSL", "false")
path := "custom-path"
clickhouse := plugin.Clickhouse{}
t.Run("should not error when valid settings passed", func(t *testing.T) {
secure := map[string]string{}
secure["password"] = password
settings := backend.DataSourceInstanceSettings{JSONData: []byte(fmt.Sprintf(`{ "server": "%s", "port": %s, "username": "%s", "secure": %s, "protocol": "http" }`, host, port, username, ssl)), DecryptedSecureJSONData: secure}
settings := backend.DataSourceInstanceSettings{JSONData: []byte(fmt.Sprintf(`{ "server": "%s", "port": %s, "path": "%s", "username": "%s", "secure": %s, "protocol": "http" }`, host, port, path, username, ssl)), DecryptedSecureJSONData: secure}
_, err := clickhouse.Connect(settings, json.RawMessage{})
assert.Equal(t, nil, err)
})
Expand Down
6 changes: 4 additions & 2 deletions pkg/plugin/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ func TestLoadSettings(t *testing.T) {
args: args{
config: backend.DataSourceInstanceSettings{
UID: "ds-uid",
JSONData: []byte(`{ "server": "foo", "port": 443, "username": "baz", "defaultDatabase":"example", "tlsSkipVerify": true, "tlsAuth" : true, "tlsAuthWithCACert": true, "timeout": "10", "enableSecureSocksProxy": true}`),
JSONData: []byte(`{ "server": "foo", "port": 443, "path": "custom-path", "username": "baz", "defaultDatabase":"example", "tlsSkipVerify": true, "tlsAuth" : true, "tlsAuthWithCACert": true, "timeout": "10", "enableSecureSocksProxy": true}`),
DecryptedSecureJSONData: map[string]string{"password": "bar", "tlsCACert": "caCert", "tlsClientCert": "clientCert", "tlsClientKey": "clientKey", "secureSocksProxyPassword": "test"},
},
},
wantSettings: Settings{
Server: "foo",
Port: 443,
Path: "custom-path",
Username: "baz",
DefaultDatabase: "example",
InsecureSkipVerify: true,
Expand Down Expand Up @@ -64,13 +65,14 @@ func TestLoadSettings(t *testing.T) {
name: "should converting string values to the correct type)",
args: args{
config: backend.DataSourceInstanceSettings{
JSONData: []byte(`{"server": "test", "port": "443", "tlsSkipVerify": "true", "tlsAuth" : "true", "tlsAuthWithCACert": "true"}`),
JSONData: []byte(`{"server": "test", "port": "443", "path": "custom-path", "tlsSkipVerify": "true", "tlsAuth" : "true", "tlsAuthWithCACert": "true"}`),
DecryptedSecureJSONData: map[string]string{},
},
},
wantSettings: Settings{
Server: "test",
Port: 443,
Path: "custom-path",
InsecureSkipVerify: true,
TlsClientAuth: true,
TlsAuthWithCACert: true,
Expand Down
14 changes: 14 additions & 0 deletions src/views/CHConfigEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('ConfigEditor', () => {
expect(screen.getByPlaceholderText(Components.ConfigEditor.ServerPort.placeholder('false'))).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.Username.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.Password.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.Path.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.DefaultDatabase.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.Timeout.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.QueryTimeout.placeholder)).toBeInTheDocument();
Expand All @@ -37,6 +38,19 @@ describe('ConfigEditor', () => {
expect(screen.getByPlaceholderText(Components.ConfigEditor.Timeout.placeholder)).toBeInTheDocument();
expect(screen.getByPlaceholderText(Components.ConfigEditor.QueryTimeout.placeholder)).toBeInTheDocument();
});
it('with path', async () => {
const path = 'custom-path';
render(
<ConfigEditor
{...mockConfigEditorProps()}
options={{
...mockConfigEditorProps().options,
jsonData: { ...mockConfigEditorProps().options.jsonData, path },
}}
/>
);
expect(screen.queryByPlaceholderText(Components.ConfigEditor.Path.placeholder)).toHaveValue(path);
});
it('with secure connection', async () => {
render(
<ConfigEditor
Expand Down

0 comments on commit 6dacbed

Please sign in to comment.