clickhouse/settings/settings_test.go

47 lines
1.1 KiB
Go
Raw Normal View History

2022-10-26 14:26:49 +03:00
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())
})
}