From 0e6fbf496b7d2a02776e2ac26589c10ed2ad26a8 Mon Sep 17 00:00:00 2001 From: Jan Graefen <223234+jangraefen@users.noreply.github.com> Date: Wed, 25 Jan 2023 21:23:54 +0100 Subject: [PATCH] chore: Add tests for new additional labels feature --- e2e/fetcher_floatingip_test.go | 13 +++++++------ e2e/fetcher_loadbalancer_test.go | 13 +++++++------ e2e/fetcher_primaryip_test.go | 24 +++++++++++++----------- e2e/fetcher_server_test.go | 26 ++++++++++++++------------ e2e/fetcher_volume_test.go | 13 +++++++------ fetcher/server.go | 2 +- fetcher/server_traffic.go | 2 +- 7 files changed, 50 insertions(+), 43 deletions(-) diff --git a/e2e/fetcher_floatingip_test.go b/e2e/fetcher_floatingip_test.go index f9ea79b..51b6869 100644 --- a/e2e/fetcher_floatingip_test.go +++ b/e2e/fetcher_floatingip_test.go @@ -11,7 +11,7 @@ import ( ) var _ = Describe("For floating IPs", Ordered, Label("floatingips"), func() { - sut := fetcher.NewFloatingIP(&fetcher.PriceProvider{Client: testClient}) + sut := fetcher.NewFloatingIP(&fetcher.PriceProvider{Client: testClient}, "suite") BeforeAll(func(ctx context.Context) { location, _, err := testClient.Location.GetByName(ctx, "fsn1") @@ -36,14 +36,15 @@ var _ = Describe("For floating IPs", Ordered, Label("floatingips"), func() { }) It("should get prices for correct values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv6"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-floatingip", "fsn1", "ipv6"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv6", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-floatingip", "fsn1", "ipv6", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) }) It("should get zero for incorrect values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "ipv6"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "nbg1", "ipv6"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv4"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "nbg1", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv4", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv6", "e3e_suite_test"))).Should(BeNumerically("==", 0)) }) }) }) diff --git a/e2e/fetcher_loadbalancer_test.go b/e2e/fetcher_loadbalancer_test.go index be39b35..ac682a9 100644 --- a/e2e/fetcher_loadbalancer_test.go +++ b/e2e/fetcher_loadbalancer_test.go @@ -11,7 +11,7 @@ import ( ) var _ = Describe("For loadbalancers", Ordered, Label("loadbalancers"), func() { - sut := fetcher.NewLoadbalancer(&fetcher.PriceProvider{Client: testClient}) + sut := fetcher.NewLoadbalancer(&fetcher.PriceProvider{Client: testClient}, "suite") BeforeAll(func(ctx context.Context) { location, _, err := testClient.Location.GetByName(ctx, "fsn1") @@ -39,14 +39,15 @@ var _ = Describe("For loadbalancers", Ordered, Label("loadbalancers"), func() { }) It("should get prices for correct values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "fsn1", "lb11"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-loadbalancer", "fsn1", "lb11"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "fsn1", "lb11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-loadbalancer", "fsn1", "lb11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) }) It("should get zero for incorrect values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "lb11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "nbg1", "lb11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "fsn1", "lb21"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "lb11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "nbg1", "lb11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "fsn1", "lb21", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-loadbalancer", "fsn1", "lb11", "e3e_suite_test"))).Should(BeNumerically("==", 0)) }) }) }) diff --git a/e2e/fetcher_primaryip_test.go b/e2e/fetcher_primaryip_test.go index b1882db..a53d756 100644 --- a/e2e/fetcher_primaryip_test.go +++ b/e2e/fetcher_primaryip_test.go @@ -11,7 +11,7 @@ import ( ) var _ = Describe("For primary IPs", Ordered, Label("primaryips"), func() { - sut := fetcher.NewPrimaryIP(&fetcher.PriceProvider{Client: testClient}) + sut := fetcher.NewPrimaryIP(&fetcher.PriceProvider{Client: testClient}, "suite") BeforeAll(func(ctx context.Context) { By("Creating a IPv4 address") @@ -50,26 +50,28 @@ var _ = Describe("For primary IPs", Ordered, Label("primaryips"), func() { It("should get prices for correct values for v4", func() { By("Checking IPv4 prices") - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) }) It("should get prices for correct values for v6", func() { By("Checking IPv6 prices") - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0.0)) - Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0.0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0.0)) + Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0.0)) }) It("should get zero for incorrect values", func() { By("Checking IPv4 prices") - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv4"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "nbg1-dc14", "ipv4"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv4", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "nbg1-dc14", "ipv4", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "fsn1-dc14", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "fsn1-dc14", "ipv4", "e3e_suite_test"))).Should(BeNumerically("==", 0)) By("Checking IPv6 prices") - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "nbg1-dc14", "ipv6"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "fsn1-dc14", "ipv4"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "nbg1-dc14", "ipv6", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "fsn1-dc14", "ipv4", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "fsn1-dc14", "ipv6", "e3e_suite_test"))).Should(BeNumerically("==", 0)) }) }) }) diff --git a/e2e/fetcher_server_test.go b/e2e/fetcher_server_test.go index f6460a3..894ef34 100644 --- a/e2e/fetcher_server_test.go +++ b/e2e/fetcher_server_test.go @@ -12,8 +12,8 @@ import ( ) var _ = Describe("For servers", Ordered, Label("servers"), func() { - sutServer := fetcher.NewServer(&fetcher.PriceProvider{Client: testClient}) - sutBackup := fetcher.NewServerBackup(&fetcher.PriceProvider{Client: testClient}) + sutServer := fetcher.NewServer(&fetcher.PriceProvider{Client: testClient}, "suite") + sutBackup := fetcher.NewServerBackup(&fetcher.PriceProvider{Client: testClient}, "suite") BeforeAll(func(ctx context.Context) { location, _, err := testClient.Location.GetByName(ctx, "fsn1") @@ -77,24 +77,26 @@ var _ = Describe("For servers", Ordered, Label("servers"), func() { It("should get prices for correct values", func() { By("Checking server prices") - Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "fsn1", "cx11"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sutServer.GetMonthly().WithLabelValues("test-server", "fsn1", "cx11"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sutServer.GetMonthly().WithLabelValues("test-server", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) By("Checking server backup prices") - Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "fsn1", "cx11"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sutBackup.GetMonthly().WithLabelValues("test-server", "fsn1", "cx11"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sutBackup.GetMonthly().WithLabelValues("test-server", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) }) It("should get zero for incorrect values", func() { By("Checking server prices") - Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("invalid-name", "fsn1", "cx11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "nbg1", "cx11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "fsn1", "cx21"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("invalid-name", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "nbg1", "cx11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "fsn1", "cx21", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutServer.GetHourly().WithLabelValues("test-server", "fsn1", "cx11", "e3e_suite_test"))).Should(BeNumerically("==", 0)) By("Checking server backup prices") - Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("invalid-name", "fsn1", "cx11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "nbg1", "cx11"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "fsn1", "cx21"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("invalid-name", "fsn1", "cx11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "nbg1", "cx11", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "fsn1", "cx21", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sutBackup.GetHourly().WithLabelValues("test-server", "fsn1", "cx11", "e3e_suite_test"))).Should(BeNumerically("==", 0)) }) }) }) diff --git a/e2e/fetcher_volume_test.go b/e2e/fetcher_volume_test.go index 24d8d78..cf6d8e5 100644 --- a/e2e/fetcher_volume_test.go +++ b/e2e/fetcher_volume_test.go @@ -11,7 +11,7 @@ import ( ) var _ = Describe("For volumes", Ordered, Label("volumes"), func() { - sut := fetcher.NewVolume(&fetcher.PriceProvider{Client: testClient}) + sut := fetcher.NewVolume(&fetcher.PriceProvider{Client: testClient}, "suite") BeforeAll(func(ctx context.Context) { location, _, err := testClient.Location.GetByName(ctx, "fsn1") @@ -36,14 +36,15 @@ var _ = Describe("For volumes", Ordered, Label("volumes"), func() { }) It("should get prices for correct values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "fsn1", "10"))).Should(BeNumerically(">", 0.0)) - Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-volume", "fsn1", "10"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "fsn1", "10", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) + Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-volume", "fsn1", "10", "e2e_suite_test"))).Should(BeNumerically(">", 0.0)) }) It("should get zero for incorrect values", func() { - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "10"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "nbg1", "10"))).Should(BeNumerically("==", 0)) - Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "fsn1", "99"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "10", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "nbg1", "10", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "fsn1", "99", "e2e_suite_test"))).Should(BeNumerically("==", 0)) + Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-volume", "fsn1", "10", "e3e_suite_test"))).Should(BeNumerically("==", 0)) }) }) }) diff --git a/fetcher/server.go b/fetcher/server.go index fcf23e4..241c5b0 100644 --- a/fetcher/server.go +++ b/fetcher/server.go @@ -10,7 +10,7 @@ var _ Fetcher = &server{} // NewServer creates a new fetcher that will collect pricing information on servers. func NewServer(pricing *PriceProvider, additionalLabels ...string) Fetcher { - return &loadBalancer{newBase(pricing, "server", []string{"location", "type"}, additionalLabels...)} + return &server{newBase(pricing, "server", []string{"location", "type"}, additionalLabels...)} } type server struct { diff --git a/fetcher/server_traffic.go b/fetcher/server_traffic.go index f1c41bc..d924439 100644 --- a/fetcher/server_traffic.go +++ b/fetcher/server_traffic.go @@ -10,7 +10,7 @@ var _ Fetcher = &serverTraffic{} // NewServerTraffic creates a new fetcher that will collect pricing information on server traffic. func NewServerTraffic(pricing *PriceProvider, additionalLabels ...string) Fetcher { - return &loadBalancer{newBase(pricing, "server_traffic", []string{"location", "type"}, additionalLabels...)} + return &serverTraffic{newBase(pricing, "server_traffic", []string{"location", "type"}, additionalLabels...)} } type serverTraffic struct {