mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-09-20 06:22:03 +00:00
50 lines
2 KiB
Go
50 lines
2 KiB
Go
package e2e_test
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hetznercloud/hcloud-go/hcloud"
|
|
"github.com/jangraefen/hcloud-pricing-exporter/fetcher"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
)
|
|
|
|
var _ = Describe("For floating IPs", Ordered, Label("floatingips"), func() {
|
|
sut := fetcher.NewFloatingIP(&fetcher.PriceProvider{Client: testClient}, "suite")
|
|
|
|
BeforeAll(func(ctx context.Context) {
|
|
location, _, err := testClient.Location.GetByName(ctx, "fsn1")
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
res, _, err := testClient.FloatingIP.Create(ctx, hcloud.FloatingIPCreateOpts{
|
|
Name: hcloud.Ptr("test-floatingip"),
|
|
Labels: testLabels,
|
|
HomeLocation: location,
|
|
Type: hcloud.FloatingIPTypeIPv6,
|
|
})
|
|
Expect(err).ShouldNot(HaveOccurred())
|
|
DeferCleanup(testClient.FloatingIP.Delete, res.FloatingIP)
|
|
|
|
waitUntilActionSucceeds(ctx, res.Action)
|
|
})
|
|
|
|
//nolint:dupl
|
|
When("getting prices", func() {
|
|
It("should fetch them", func() {
|
|
Expect(sut.Run(testClient)).To(Succeed())
|
|
})
|
|
|
|
It("should get prices for correct values", func() {
|
|
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", "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))
|
|
})
|
|
})
|
|
})
|