From e8214869deaf275f0c7950c4eb808735d653fb7b Mon Sep 17 00:00:00 2001 From: Georges Chaudy Date: Mon, 8 Jul 2024 23:51:14 +0200 Subject: [PATCH] add resource_history_list test --- pkg/storage/unified/sql/queries_test.go | 23 +++++++++++++++++++ .../resource_history_list_mysql_sqlite.sql | 11 +++++++++ 2 files changed, 34 insertions(+) create mode 100644 pkg/storage/unified/sql/testdata/resource_history_list_mysql_sqlite.sql diff --git a/pkg/storage/unified/sql/queries_test.go b/pkg/storage/unified/sql/queries_test.go index da4cf1eb3b3..1b1a90f06ec 100644 --- a/pkg/storage/unified/sql/queries_test.go +++ b/pkg/storage/unified/sql/queries_test.go @@ -185,6 +185,29 @@ func TestQueries(t *testing.T) { }, }, }, + sqlResourceHistoryList: { + { + Name: "single path", + Data: &sqlResourceHistoryListRequest{ + SQLTemplate: new(sqltemplate.SQLTemplate), + Request: &historyListRequest{ + Limit: 10, + Options: &resource.ListOptions{ + Key: &resource.ResourceKey{ + Namespace: "ns", + }, + }, + }, + Response: new(resource.ResourceWrapper), + }, + Expected: expected{ + "resource_history_list_mysql_sqlite.sql": dialects{ + sqltemplate.MySQL, + sqltemplate.SQLite, + }, + }, + }, + }, sqlResourceUpdateRV: { { Name: "single path", diff --git a/pkg/storage/unified/sql/testdata/resource_history_list_mysql_sqlite.sql b/pkg/storage/unified/sql/testdata/resource_history_list_mysql_sqlite.sql new file mode 100644 index 00000000000..1e7b7c144b9 --- /dev/null +++ b/pkg/storage/unified/sql/testdata/resource_history_list_mysql_sqlite.sql @@ -0,0 +1,11 @@ +SELECT kv."resource_version", "value" +FROM "resource_history" as kv +JOIN ( + SELECT "guid", max("resource_version") AS "resource_version" + FROM "resource_history" AS mkv + WHERE 1 = 1 AND "resource_version" <= ? AND "namespace" = ? + GROUP BY mkv."namespace", mkv."group", mkv."resource", mkv."name" +) AS maxkv ON maxkv."guid" = kv."guid" +WHERE kv."action" != 3 +ORDER BY kv."resource_version" ASC +LIMIT ?, ?; \ No newline at end of file