test(outputs.sql): Fix integration tests (#16543)
This commit is contained in:
parent
cb71790cf7
commit
edb28dea07
|
|
@ -188,8 +188,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
wait.ForLog("mariadbd: ready for connections.").WithOccurrence(2),
|
||||
),
|
||||
}
|
||||
err = container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
require.NoError(t, container.Start(), "failed to start container")
|
||||
defer container.Terminate()
|
||||
|
||||
// use the plugin to write to the database
|
||||
|
|
@ -203,19 +202,15 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
p.InitSQL = "SET sql_mode='ANSI_QUOTES';"
|
||||
|
||||
require.NoError(t, p.Connect())
|
||||
require.NoError(t, p.Write(
|
||||
testMetrics,
|
||||
))
|
||||
require.NoError(t, p.Write(testMetrics))
|
||||
|
||||
cases := []struct {
|
||||
expectedFile string
|
||||
}{
|
||||
{"./testdata/mariadb/expected_metric_one.sql"},
|
||||
{"./testdata/mariadb/expected_metric_two.sql"},
|
||||
{"./testdata/mariadb/expected_metric_three.sql"},
|
||||
files := []string{
|
||||
"./testdata/mariadb/expected_metric_one.sql",
|
||||
"./testdata/mariadb/expected_metric_two.sql",
|
||||
"./testdata/mariadb/expected_metric_three.sql",
|
||||
}
|
||||
for _, tc := range cases {
|
||||
expected, err := os.ReadFile(tc.expectedFile)
|
||||
for _, fn := range files {
|
||||
expected, err := os.ReadFile(fn)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
|
|
@ -224,7 +219,8 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
"-c",
|
||||
"mariadb-dump --user=" + username +
|
||||
" --password=" + password +
|
||||
" --compact --skip-opt " +
|
||||
" --compact" +
|
||||
" --skip-opt " +
|
||||
dbname,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -234,7 +230,7 @@ func TestMysqlIntegration(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
return bytes.Contains(b, expected)
|
||||
}, 10*time.Second, 500*time.Millisecond, tc.expectedFile)
|
||||
}, 10*time.Second, 500*time.Millisecond, fn)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -271,8 +267,7 @@ func TestPostgresIntegration(t *testing.T) {
|
|||
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
|
||||
),
|
||||
}
|
||||
err = container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
require.NoError(t, container.Start(), "failed to start container")
|
||||
defer container.Terminate()
|
||||
|
||||
// use the plugin to write to the database
|
||||
|
|
@ -290,9 +285,7 @@ func TestPostgresIntegration(t *testing.T) {
|
|||
|
||||
require.NoError(t, p.Connect())
|
||||
defer p.Close()
|
||||
require.NoError(t, p.Write(
|
||||
testMetrics,
|
||||
))
|
||||
require.NoError(t, p.Write(testMetrics))
|
||||
require.NoError(t, p.Close())
|
||||
|
||||
expected, err := os.ReadFile("./testdata/postgres/expected.sql")
|
||||
|
|
@ -304,10 +297,7 @@ func TestPostgresIntegration(t *testing.T) {
|
|||
"-c",
|
||||
"pg_dump" +
|
||||
" --username=" + username +
|
||||
// " --password=" + password +
|
||||
// " --compact --skip-opt " +
|
||||
" --no-comments" +
|
||||
// " --data-only" +
|
||||
" " + dbname +
|
||||
// pg_dump's output has comments that include build info
|
||||
// of postgres and pg_dump. The build info changes with
|
||||
|
|
@ -340,15 +330,20 @@ func TestClickHouseIntegration(t *testing.T) {
|
|||
// initdb/init.sql creates this database
|
||||
const dbname = "foo"
|
||||
|
||||
// default username for clickhouse is default
|
||||
const username = "default"
|
||||
// username for connecting to clickhouse
|
||||
const username = "clickhouse"
|
||||
|
||||
password := pwgen(32)
|
||||
outDir := t.TempDir()
|
||||
|
||||
servicePort := "9000"
|
||||
container := testutil.Container{
|
||||
Image: "clickhouse",
|
||||
ExposedPorts: []string{servicePort, "8123"},
|
||||
Env: map[string]string{
|
||||
"CLICKHOUSE_USER": "clickhouse",
|
||||
"CLICKHOUSE_PASSWORD": password,
|
||||
},
|
||||
Files: map[string]string{
|
||||
"/docker-entrypoint-initdb.d/script.sql": initdb,
|
||||
"/etc/clickhouse-server/config.d/enable_stdout_log.xml": logConfig,
|
||||
|
|
@ -360,14 +355,13 @@ func TestClickHouseIntegration(t *testing.T) {
|
|||
wait.ForLog("Ready for connections"),
|
||||
),
|
||||
}
|
||||
err = container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
require.NoError(t, container.Start(), "failed to start container")
|
||||
defer container.Terminate()
|
||||
|
||||
// use the plugin to write to the database
|
||||
// host, port, username, password, dbname
|
||||
address := fmt.Sprintf("tcp://%v:%v/%v?username=%v",
|
||||
container.Address, container.Ports[servicePort], dbname, username)
|
||||
address := fmt.Sprintf("tcp://%s:%s/%s?username=%s&password=%s",
|
||||
container.Address, container.Ports[servicePort], dbname, username, password)
|
||||
p := newSQL()
|
||||
p.Log = testutil.Logger{}
|
||||
p.Driver = "clickhouse"
|
||||
|
|
@ -402,9 +396,8 @@ func TestClickHouseIntegration(t *testing.T) {
|
|||
" --user=" + username +
|
||||
" --database=" + dbname +
|
||||
" --format=TabSeparatedRaw" +
|
||||
" --multiquery --query=" +
|
||||
"\"SELECT * FROM \\\"" + tc.table + "\\\";" +
|
||||
"SHOW CREATE TABLE \\\"" + tc.table + "\\\"\"",
|
||||
" --multiquery" +
|
||||
` --query="SELECT * FROM \"` + tc.table + `\"; SHOW CREATE TABLE \"` + tc.table + `\""`,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
b, err := io.ReadAll(out)
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `bar` (
|
||||
`baz` int(11) DEFAULT NULL
|
||||
);
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
INSERT INTO `bar` VALUES (1);
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `metric three` (
|
||||
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`tag four` text DEFAULT NULL,
|
||||
`string two` text DEFAULT NULL
|
||||
);
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
INSERT INTO `metric three` VALUES ('2021-05-17 22:04:45','tag4','string2');
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `metric_one` (
|
||||
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`tag_one` text DEFAULT NULL,
|
||||
`tag_two` text DEFAULT NULL,
|
||||
`int64_one` int(11) DEFAULT NULL,
|
||||
`int64_two` int(11) DEFAULT NULL,
|
||||
`bool_one` tinyint(1) DEFAULT NULL,
|
||||
`bool_two` tinyint(1) DEFAULT NULL,
|
||||
`uint64_one` int(10) unsigned DEFAULT NULL,
|
||||
`float64_one` double DEFAULT NULL
|
||||
);
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
INSERT INTO `metric_one` VALUES ('2021-05-17 22:04:45','tag1','tag2',1234,2345,1,0,1000000000,3.1415);
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `metric_two` (
|
||||
`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`tag_three` text DEFAULT NULL,
|
||||
`string_one` text DEFAULT NULL
|
||||
);
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
INSERT INTO `metric_two` VALUES ('2021-05-17 22:04:45','tag3','string1');
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/*!40101 SET character_set_client = utf8 */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `metric_one` (
|
||||
`timestamp` timestamp NULL DEFAULT NULL,
|
||||
`tag_one` text DEFAULT NULL,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*!40101 SET character_set_client = utf8 */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `metric three` (
|
||||
`timestamp` timestamp NULL DEFAULT NULL,
|
||||
`tag four` text DEFAULT NULL,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*!40101 SET character_set_client = utf8 */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `metric_two` (
|
||||
`timestamp` timestamp NULL DEFAULT NULL,
|
||||
`tag_three` text DEFAULT NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue