Skip to content

Commit

Permalink
Move around collectr tests and update test get platform to use pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Mar 12, 2024
1 parent eebc2c6 commit 3ff7df2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
42 changes: 21 additions & 21 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions internal/mode/static/telemetry/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -84,15 +84,15 @@ 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"},
},
Spec: v1.NodeSpec{
ProviderID: "k3s://ip-172-16-0-210",
},
},
namespaces: v1.NamespaceList{},
namespaces: &v1.NamespaceList{},
expectedPlatform: "openshift",
name: "openshift platform",
},
Expand All @@ -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))
})
}
Expand Down

0 comments on commit 3ff7df2

Please sign in to comment.