From 3ff7df23892db475d39044b2a0e3eeceb5a9b5c9 Mon Sep 17 00:00:00 2001 From: Benjamin Jee Date: Mon, 11 Mar 2024 17:43:31 -0700 Subject: [PATCH] Move around collectr tests and update test get platform to use pointers --- .../mode/static/telemetry/collector_test.go | 42 +++++++++---------- .../mode/static/telemetry/platform_test.go | 34 +++++++-------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 99d39782b2..df53661eef 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -340,6 +340,27 @@ var _ = Describe("Collector", Ordered, func() { }) }) + Describe("clusterID collector", func() { + When("collecting clusterID data", func() { + When("it encounters an error while collecting data", func() { + It("should error if the kubernetes client errored when getting the namespace", func() { + expectedError := errors.New("there was an error getting clusterID") + k8sClientReader.GetCalls(mergeGetCallsWithBase( + func(_ context.Context, _ types.NamespacedName, object client.Object, _ ...client.GetOption) error { + switch object.(type) { + case *v1.Namespace: + return expectedError + } + return nil + })) + + _, err := dataCollector.Collect(ctx) + Expect(err).To(MatchError(expectedError)) + }) + }) + }) + }) + Describe("node count collector", func() { When("collecting node count data", func() { It("collects correct data for one node", func() { @@ -403,27 +424,6 @@ var _ = Describe("Collector", Ordered, func() { }) }) - Describe("clusterID collector", func() { - When("collecting clusterID data", func() { - When("it encounters an error while collecting data", func() { - It("should error if the kubernetes client errored when getting the namespace", func() { - expectedError := errors.New("there was an error getting clusterID") - k8sClientReader.GetCalls(mergeGetCallsWithBase( - func(_ context.Context, _ types.NamespacedName, object client.Object, _ ...client.GetOption) error { - switch object.(type) { - case *v1.Namespace: - return expectedError - } - return nil - })) - - _, err := dataCollector.Collect(ctx) - Expect(err).To(MatchError(expectedError)) - }) - }) - }) - }) - Describe("NGF resource count collector", func() { var ( graph1 *graph.Graph diff --git a/internal/mode/static/telemetry/platform_test.go b/internal/mode/static/telemetry/platform_test.go index 794b35ff48..9ca82eee14 100644 --- a/internal/mode/static/telemetry/platform_test.go +++ b/internal/mode/static/telemetry/platform_test.go @@ -10,68 +10,68 @@ import ( func TestGetPlatform(t *testing.T) { tests := []struct { + node *v1.Node + namespaces *v1.NamespaceList expectedPlatform string name string - node v1.Node - namespaces v1.NamespaceList }{ { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "kind://docker/kind/kind-control-plane", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "kind", name: "kind platform", }, { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "k3s://ip-172-16-0-210", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "k3s", name: "k3s platform", }, { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "gce://test-data/us-central1-c/test-data", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "gke", name: "gke platform", }, { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "azure://test-data/us-central1-c/test-data", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "aks", name: "aks platform", }, { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "aws://test-data/us-central1-c/test-data", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "eks", name: "eks platform", }, { - node: v1.Node{ + node: &v1.Node{ Spec: v1.NodeSpec{ ProviderID: "k3s://ip-172-16-0-210", }, }, - namespaces: v1.NamespaceList{ + namespaces: &v1.NamespaceList{ Items: []v1.Namespace{ { ObjectMeta: metav1.ObjectMeta{ @@ -84,7 +84,7 @@ func TestGetPlatform(t *testing.T) { name: "rancher platform", }, { - node: v1.Node{ + node: &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"node.openshift.io/os_id": "test"}, }, @@ -92,7 +92,7 @@ func TestGetPlatform(t *testing.T) { ProviderID: "k3s://ip-172-16-0-210", }, }, - namespaces: v1.NamespaceList{}, + namespaces: &v1.NamespaceList{}, expectedPlatform: "openshift", name: "openshift platform", }, @@ -101,7 +101,7 @@ func TestGetPlatform(t *testing.T) { t.Run(test.name, func(t *testing.T) { g := NewWithT(t) - platform := getPlatform(test.node, test.namespaces) + platform := getPlatform(*test.node, *test.namespaces) g.Expect(platform).To(Equal(test.expectedPlatform)) }) }