47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
|
package settings_test
|
||
|
|
||
|
import (
|
||
|
"clickhouse/settings"
|
||
|
"encoding/json"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestLoad(t *testing.T) {
|
||
|
expectedSettings := settings.ClickhouseSettings{
|
||
|
Host: "localhost",
|
||
|
Port: 9000,
|
||
|
Database: "regency_dev",
|
||
|
Options: map[string]json.RawMessage{
|
||
|
"read_timeout": json.RawMessage(`1`),
|
||
|
"no_delay": json.RawMessage(`"disable"`),
|
||
|
},
|
||
|
}
|
||
|
|
||
|
actualSettings, err := settings.Load("./test_settings.json")
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
assert.Equal(t, expectedSettings, actualSettings)
|
||
|
|
||
|
}
|
||
|
func TestClickhouseSettings(t *testing.T) {
|
||
|
t.Run("DSN", func(t *testing.T) {
|
||
|
clickSettings := settings.ClickhouseSettings{
|
||
|
Host: "localhost",
|
||
|
Port: 9000,
|
||
|
Username: "user",
|
||
|
Password: "pwd#1",
|
||
|
Database: "regency_dev",
|
||
|
Options: map[string]json.RawMessage{
|
||
|
"read_timeout": json.RawMessage(`1`),
|
||
|
"no_delay": json.RawMessage(`"disable"`),
|
||
|
},
|
||
|
}
|
||
|
|
||
|
expectedDSN := "tcp://localhost:9000?database=regency_dev&no_delay=disable&password=pwd%231&read_timeout=1&username=user"
|
||
|
|
||
|
assert.Equal(t, expectedDSN, clickSettings.DSN())
|
||
|
})
|
||
|
}
|