Skip to content

Commit

Permalink
PMM-12896 Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Mar 14, 2024
1 parent af550fb commit 06743cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
17 changes: 3 additions & 14 deletions agent/runner/actions/mysql_explain_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,8 @@ func TestMySQLExplain(t *testing.T) {
OutputFormat: agentpb.MysqlExplainOutputFormat_MYSQL_EXPLAIN_OUTPUT_FORMAT_DEFAULT,
}
a, err := NewMySQLExplainAction("", time.Second, params)
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), a.Timeout())
defer cancel()

_, err = a.Run(ctx)
require.Error(t, err)
assert.Regexp(t, `Query to EXPLAIN is empty`, err.Error())
assert.Nil(t, a)
})

t.Run("DML Query Insert", func(t *testing.T) {
Expand Down Expand Up @@ -216,13 +210,8 @@ func TestMySQLExplain(t *testing.T) {
OutputFormat: agentpb.MysqlExplainOutputFormat_MYSQL_EXPLAIN_OUTPUT_FORMAT_DEFAULT,
}
a, err := NewMySQLExplainAction("", time.Second, params)
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), a.Timeout())
defer cancel()

_, err = a.Run(ctx)
require.Error(t, err, "EXPLAIN failed because the query was too long and trimmed. Set max-query-length to a larger value.")
assert.Error(t, err, "EXPLAIN failed because the query was too long and trimmed. Set max-query-length to a larger value.")
assert.Nil(t, a)
})

t.Run("LittleBobbyTables", func(t *testing.T) {
Expand Down
13 changes: 1 addition & 12 deletions agent/runner/actions/postgresql_query_select_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,7 @@ func TestPostgreSQLQuerySelect(t *testing.T) {
Query: "* FROM city; DROP TABLE city CASCADE; --",
}
a, err := NewPostgreSQLQuerySelectAction("", 0, params, os.TempDir())
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

b, err := a.Run(ctx)
assert.EqualError(t, err, "query contains ';'")
assert.Nil(t, b)

var count int
err = db.QueryRow("SELECT COUNT(*) FROM city").Scan(&count)
require.NoError(t, err)
assert.Equal(t, 4079, count)
assert.Nil(t, a)
})
}

0 comments on commit 06743cf

Please sign in to comment.