test(outputs.sql): do not write to file during testing (#12203)
This commit is contained in:
parent
6cfae2a1fd
commit
ea9aa38d23
|
|
@ -209,31 +209,35 @@ func TestMysqlIntegration(t *testing.T) {
|
||||||
testMetrics,
|
testMetrics,
|
||||||
))
|
))
|
||||||
|
|
||||||
//dump the database
|
cases := []struct {
|
||||||
var rc int
|
expectedFile string
|
||||||
rc, _, err = container.Exec([]string{
|
}{
|
||||||
"bash",
|
{"./testdata/mariadb/expected_metric_one.sql"},
|
||||||
"-c",
|
{"./testdata/mariadb/expected_metric_two.sql"},
|
||||||
"mariadb-dump --user=" + username +
|
{"./testdata/mariadb/expected_metric_three.sql"},
|
||||||
" --password=" + password +
|
}
|
||||||
" --compact --skip-opt " +
|
for _, tc := range cases {
|
||||||
dbname +
|
expected, err := os.ReadFile(tc.expectedFile)
|
||||||
" > /out/dump",
|
require.NoError(t, err)
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, 0, rc)
|
|
||||||
dumpfile := filepath.Join(outDir, "dump")
|
|
||||||
require.Eventually(t, func() bool {
|
|
||||||
_, err := os.Stat(dumpfile)
|
|
||||||
return !os.IsNotExist(err)
|
|
||||||
}, 5*time.Second, 10*time.Millisecond)
|
|
||||||
|
|
||||||
//compare the dump to what we expected
|
require.Eventually(t, func() bool {
|
||||||
expected, err := os.ReadFile("testdata/mariadb/expected.sql")
|
rc, out, err := container.Exec([]string{
|
||||||
require.NoError(t, err)
|
"bash",
|
||||||
actual, err := os.ReadFile(dumpfile)
|
"-c",
|
||||||
require.NoError(t, err)
|
"mariadb-dump --user=" + username +
|
||||||
require.Equal(t, string(expected), string(actual))
|
" --password=" + password +
|
||||||
|
" --compact --skip-opt " +
|
||||||
|
dbname,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 0, rc)
|
||||||
|
|
||||||
|
bytes, err := io.ReadAll(out)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return strings.Contains(string(bytes), string(expected))
|
||||||
|
}, 5*time.Second, 500*time.Millisecond)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostgresIntegration(t *testing.T) {
|
func TestPostgresIntegration(t *testing.T) {
|
||||||
|
|
@ -291,38 +295,35 @@ func TestPostgresIntegration(t *testing.T) {
|
||||||
testMetrics,
|
testMetrics,
|
||||||
))
|
))
|
||||||
|
|
||||||
//dump the database
|
expected, err := os.ReadFile("./testdata/postgres/expected.sql")
|
||||||
//psql -u postgres
|
|
||||||
var rc int
|
|
||||||
rc, _, err = container.Exec([]string{
|
|
||||||
"bash",
|
|
||||||
"-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
|
|
||||||
// each release. To prevent these changes from causing the
|
|
||||||
// test to fail, we strip out comments. Also strip out
|
|
||||||
// blank lines.
|
|
||||||
"|grep -E -v '(^--|^$)'" +
|
|
||||||
" > /out/dump 2>&1",
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 0, rc)
|
|
||||||
dumpfile := filepath.Join(outDir, "dump")
|
|
||||||
require.FileExists(t, dumpfile)
|
|
||||||
|
|
||||||
//compare the dump to what we expected
|
require.Eventually(t, func() bool {
|
||||||
expected, err := os.ReadFile("testdata/postgres/expected.sql")
|
rc, out, err := container.Exec([]string{
|
||||||
require.NoError(t, err)
|
"bash",
|
||||||
actual, err := os.ReadFile(dumpfile)
|
"-c",
|
||||||
require.NoError(t, err)
|
"pg_dump" +
|
||||||
require.Equal(t, string(expected), string(actual))
|
" --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
|
||||||
|
// each release. To prevent these changes from causing the
|
||||||
|
// test to fail, we strip out comments. Also strip out
|
||||||
|
// blank lines.
|
||||||
|
"|grep -E -v '(^--|^$)'",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 0, rc)
|
||||||
|
|
||||||
|
bytes, err := io.ReadAll(out)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return strings.Contains(string(bytes), string(expected))
|
||||||
|
}, 5*time.Second, 500*time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClickHouseIntegration(t *testing.T) {
|
func TestClickHouseIntegration(t *testing.T) {
|
||||||
|
|
@ -406,6 +407,6 @@ func TestClickHouseIntegration(t *testing.T) {
|
||||||
bytes, err := io.ReadAll(out)
|
bytes, err := io.ReadAll(out)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return strings.Contains(string(bytes), tc.expected)
|
return strings.Contains(string(bytes), tc.expected)
|
||||||
}, 5*time.Second, 10*time.Millisecond)
|
}, 5*time.Second, 500*time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*!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);
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*!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');
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*!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');
|
||||||
Loading…
Reference in New Issue