From f7d94b4b8a56fd22070493bcf26fcabd563111f1 Mon Sep 17 00:00:00 2001 From: Nutmos Date: Tue, 24 Dec 2024 20:00:36 +0700 Subject: [PATCH] Refactor LightSailSDConfig (#7231) * add test case --- test/e2e/scrapeconfig_test.go | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/e2e/scrapeconfig_test.go b/test/e2e/scrapeconfig_test.go index 48441979e..31163f500 100644 --- a/test/e2e/scrapeconfig_test.go +++ b/test/e2e/scrapeconfig_test.go @@ -610,6 +610,9 @@ func testScrapeConfigCRDValidations(t *testing.T) { t.Run("IonosSD", func(t *testing.T) { runScrapeConfigCRDValidation(t, IonosSDTestCases) }) + t.Run("LightSailSD", func(t *testing.T) { + runScrapeConfigCRDValidation(t, LightSailSDTestCases) + }) } func runScrapeConfigCRDValidation(t *testing.T, testCases []scrapeCRDTestCase) { @@ -2035,3 +2038,84 @@ var IonosSDTestCases = []scrapeCRDTestCase{ expectedError: true, }, } + +var LightSailSDTestCases = []scrapeCRDTestCase{ + { + name: "Valid RegionID", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Region: ptr.To("us-east-1"), + }, + }, + }, + expectedError: false, + }, + { + name: "Invalid RegionID", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Region: ptr.To(""), + }, + }, + }, + expectedError: true, + }, + { + name: "Valid Endpoint", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Endpoint: ptr.To("https://custom-endpoint.example.com"), + }, + }, + }, + expectedError: false, + }, + + { + name: "Invalid Endpoint", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Endpoint: ptr.To(""), + }, + }, + }, + expectedError: true, + }, + { + name: "Valid Port", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Port: ptr.To(int32(80)), + }, + }, + }, + expectedError: false, + }, + { + name: "Invalid Port 1", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Port: ptr.To(int32(-1)), + }, + }, + }, + expectedError: true, + }, + { + name: "Invalid Port 2", + scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{ + LightSailSDConfigs: []monitoringv1alpha1.LightSailSDConfig{ + { + Port: ptr.To(int32(65536)), + }, + }, + }, + expectedError: true, + }, +}