test(outputs.sql): do not write to file during testing (#12203)

This commit is contained in:
Joshua Powers 2022-11-18 07:22:46 -07:00 committed by GitHub
parent 6cfae2a1fd
commit ea9aa38d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 55 deletions

View File

@ -209,31 +209,35 @@ func TestMysqlIntegration(t *testing.T) {
testMetrics,
))
//dump the database
var rc int
rc, _, err = container.Exec([]string{
"bash",
"-c",
"mariadb-dump --user=" + username +
" --password=" + password +
" --compact --skip-opt " +
dbname +
" > /out/dump",
})
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)
cases := []struct {
expectedFile 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)
require.NoError(t, err)
//compare the dump to what we expected
expected, err := os.ReadFile("testdata/mariadb/expected.sql")
require.NoError(t, err)
actual, err := os.ReadFile(dumpfile)
require.NoError(t, err)
require.Equal(t, string(expected), string(actual))
require.Eventually(t, func() bool {
rc, out, err := container.Exec([]string{
"bash",
"-c",
"mariadb-dump --user=" + username +
" --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) {
@ -291,38 +295,35 @@ func TestPostgresIntegration(t *testing.T) {
testMetrics,
))
//dump the database
//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",
})
expected, err := os.ReadFile("./testdata/postgres/expected.sql")
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
expected, err := os.ReadFile("testdata/postgres/expected.sql")
require.NoError(t, err)
actual, err := os.ReadFile(dumpfile)
require.NoError(t, err)
require.Equal(t, string(expected), string(actual))
require.Eventually(t, func() bool {
rc, out, 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 '(^--|^$)'",
})
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) {
@ -406,6 +407,6 @@ func TestClickHouseIntegration(t *testing.T) {
bytes, err := io.ReadAll(out)
require.NoError(t, err)
return strings.Contains(string(bytes), tc.expected)
}, 5*time.Second, 10*time.Millisecond)
}, 5*time.Second, 500*time.Millisecond)
}
}

View File

@ -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);

View File

@ -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');

View File

@ -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');