From b2f5616af4bbb02b1cad4ca49db65e9538d30705 Mon Sep 17 00:00:00 2001 From: dblock Date: Tue, 20 Aug 2024 08:47:51 -0400 Subject: [PATCH] Fix: skip if below or equal test cases. Signed-off-by: dblock --- internal/test/helper.go | 6 +++--- opensearchapi/api_cat_test.go | 4 ++-- opensearchapi/api_cluster_test.go | 2 +- opensearchapi/api_point_in_time_test.go | 2 +- opensearchapi/api_script_test.go | 4 ++-- plugins/ism/api_test.go | 4 ++-- plugins/security/api_ssl_test.go | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/test/helper.go b/internal/test/helper.go index ebea0ad98..8caf39a0d 100644 --- a/internal/test/helper.go +++ b/internal/test/helper.go @@ -100,12 +100,12 @@ func GetVersion(client *opensearchapi.Client) (int64, int64, int64, error) { return opensearch.ParseVersion(resp.Version.Number) } -// SkipIfBelowVersion skips a test if the cluster version is below a given version -func SkipIfBelowVersion(t *testing.T, client *opensearchapi.Client, majorVersion, patchVersion int64, testName string) { +// SkipIfBelowOrEqualVersion skips a test if the cluster version is below or equal a given version +func SkipIfBelowOrEqualVersion(t *testing.T, client *opensearchapi.Client, majorVersion, patchVersion int64, testName string) { t.Helper() major, patch, _, err := GetVersion(client) assert.Nil(t, err) - if major <= majorVersion && patch <= patchVersion { + if major < majorVersion || (major == majorVersion && patch <= patchVersion) { t.Skipf("Skiping %s as version %d.%d.x does not support this endpoint", testName, major, patch) } } diff --git a/opensearchapi/api_cat_test.go b/opensearchapi/api_cat_test.go index 223ddecd9..2909c7c9a 100644 --- a/opensearchapi/api_cat_test.go +++ b/opensearchapi/api_cat_test.go @@ -366,7 +366,7 @@ func TestCatClient(t *testing.T) { for catType, value := range testCases { t.Run(catType, func(t *testing.T) { if catType == "ClusterManager" { - ostest.SkipIfBelowVersion(t, client, 1, 3, catType) + ostest.SkipIfBelowOrEqualVersion(t, client, 1, 3, catType) } for _, testCase := range value { t.Run(testCase.Name, func(t *testing.T) { @@ -399,7 +399,7 @@ func TestCatClient(t *testing.T) { ostest.CompareRawJSONwithParsedJSON(t, resp.Allocations, resp.Inspect().Response) }) t.Run("ClusterManager", func(t *testing.T) { - ostest.SkipIfBelowVersion(t, client, 1, 3, "ClusterManager") + ostest.SkipIfBelowOrEqualVersion(t, client, 1, 3, "ClusterManager") resp, err := client.Cat.ClusterManager(nil, nil) assert.Nil(t, err) assert.NotNil(t, resp) diff --git a/opensearchapi/api_cluster_test.go b/opensearchapi/api_cluster_test.go index a2c65085b..f89b55d9b 100644 --- a/opensearchapi/api_cluster_test.go +++ b/opensearchapi/api_cluster_test.go @@ -230,7 +230,7 @@ func TestClusterClient(t *testing.T) { for catType, value := range testCases { t.Run(catType, func(t *testing.T) { if strings.Contains(catType, "Decommission") { - ostest.SkipIfBelowVersion(t, client, 2, 3, catType) + ostest.SkipIfBelowOrEqualVersion(t, client, 2, 3, catType) } for _, testCase := range value { t.Run(testCase.Name, func(t *testing.T) { diff --git a/opensearchapi/api_point_in_time_test.go b/opensearchapi/api_point_in_time_test.go index c642a8ffe..bef8ac604 100644 --- a/opensearchapi/api_point_in_time_test.go +++ b/opensearchapi/api_point_in_time_test.go @@ -23,7 +23,7 @@ import ( func TestPointInTimeClient(t *testing.T) { client, err := ostest.NewClient() require.Nil(t, err) - ostest.SkipIfBelowVersion(t, client, 2, 4, "Point_In_Time") + ostest.SkipIfBelowOrEqualVersion(t, client, 2, 4, "Point_In_Time") failingClient, err := osapitest.CreateFailingClient() require.Nil(t, err) diff --git a/opensearchapi/api_script_test.go b/opensearchapi/api_script_test.go index 317e3cb96..551bdc387 100644 --- a/opensearchapi/api_script_test.go +++ b/opensearchapi/api_script_test.go @@ -155,7 +155,7 @@ func TestScriptClient(t *testing.T) { for _, value := range testCases { t.Run(value.Name, func(t *testing.T) { if strings.Contains(value.Name, "Language") { - ostest.SkipIfBelowVersion(t, client, 2, 3, value.Name) + ostest.SkipIfBelowOrEqualVersion(t, client, 2, 3, value.Name) } for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { @@ -206,7 +206,7 @@ func TestScriptClient(t *testing.T) { ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response) }) t.Run("Language", func(t *testing.T) { - ostest.SkipIfBelowVersion(t, client, 2, 3, "Language") + ostest.SkipIfBelowOrEqualVersion(t, client, 2, 3, "Language") resp, err := client.Script.Language(nil, nil) require.Nil(t, err) assert.NotNil(t, resp) diff --git a/plugins/ism/api_test.go b/plugins/ism/api_test.go index 0ff4f2b93..defa61647 100644 --- a/plugins/ism/api_test.go +++ b/plugins/ism/api_test.go @@ -243,14 +243,14 @@ func TestClient(t *testing.T) { ostest.CompareRawJSONwithParsedJSON(t, &resp, resp.Inspect().Response) }) t.Run("Explain with validate_action", func(t *testing.T) { - ostest.SkipIfBelowVersion(t, osClient, 2, 3, "Explain with validate_action") + ostest.SkipIfBelowOrEqualVersion(t, osClient, 2, 3, "Explain with validate_action") resp, err := client.Explain(nil, &ism.ExplainReq{Indices: testIndex, Params: ism.ExplainParams{ShowPolicy: true, ValidateAction: true}}) assert.Nil(t, err) assert.NotNil(t, resp) ostest.CompareRawJSONwithParsedJSON(t, &resp, resp.Inspect().Response) }) t.Run("Explain with show_policy", func(t *testing.T) { - ostest.SkipIfBelowVersion(t, osClient, 1, 2, "Explain with validate_action") + ostest.SkipIfBelowOrEqualVersion(t, osClient, 1, 2, "Explain with validate_action") resp, err := client.Explain(nil, &ism.ExplainReq{Indices: testIndex, Params: ism.ExplainParams{ShowPolicy: true}}) assert.Nil(t, err) assert.NotNil(t, resp) diff --git a/plugins/security/api_ssl_test.go b/plugins/security/api_ssl_test.go index ea89ea25e..c31efb0e8 100644 --- a/plugins/security/api_ssl_test.go +++ b/plugins/security/api_ssl_test.go @@ -30,7 +30,7 @@ func TestSSLClient(t *testing.T) { osAPIclient, err := ostest.NewClient() require.Nil(t, err) - ostest.SkipIfBelowVersion(t, osAPIclient, 1, 3, "SSLClient") + ostest.SkipIfBelowOrEqualVersion(t, osAPIclient, 1, 3, "SSLClient") clientTLSCert, err := tls.LoadX509KeyPair("../../admin.pem", "../../admin.key") require.Nil(t, err) @@ -114,7 +114,7 @@ func TestSSLClient(t *testing.T) { for _, testCase := range value.Tests { t.Run(testCase.Name, func(t *testing.T) { if strings.HasSuffix(value.Name, "Reload") && strings.Contains(testCase.Name, "request") { - ostest.SkipIfBelowVersion(t, osAPIclient, 2, 7, value.Name) + ostest.SkipIfBelowOrEqualVersion(t, osAPIclient, 2, 7, value.Name) } res, err := testCase.Results() if testCase.Name == "inspect" {