mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-10 05:54:15 +00:00
chore: Add tests for new additional labels feature
This commit is contained in:
parent
fca0b5f77b
commit
0e6fbf496b
7 changed files with 50 additions and 43 deletions
|
@ -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))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue