-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move platform tests to unit test and adjust collector tests
- Loading branch information
Showing
2 changed files
with
114 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package telemetry | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestGetPlatform(t *testing.T) { | ||
tests := []struct { | ||
expectedPlatform string | ||
name string | ||
node v1.Node | ||
namespaces v1.NamespaceList | ||
}{ | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "kind://docker/kind/kind-control-plane", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{}, | ||
expectedPlatform: "kind", | ||
name: "kind platform", | ||
}, | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "k3s://ip-172-16-0-210", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{}, | ||
expectedPlatform: "k3s", | ||
name: "k3s platform", | ||
}, | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "gce://test-data/us-central1-c/test-data", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{}, | ||
expectedPlatform: "gke", | ||
name: "gke platform", | ||
}, | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "azure://test-data/us-central1-c/test-data", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{}, | ||
expectedPlatform: "aks", | ||
name: "aks platform", | ||
}, | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "aws://test-data/us-central1-c/test-data", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{}, | ||
expectedPlatform: "eks", | ||
name: "eks platform", | ||
}, | ||
{ | ||
node: v1.Node{ | ||
Spec: v1.NodeSpec{ | ||
ProviderID: "k3s://ip-172-16-0-210", | ||
}, | ||
}, | ||
namespaces: v1.NamespaceList{ | ||
Items: []v1.Namespace{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "cattle-system", | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedPlatform: "rancher", | ||
name: "rancher platform", | ||
}, | ||
{ | ||
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{}, | ||
expectedPlatform: "openshift", | ||
name: "openshift platform", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
platform := getPlatform(test.node, test.namespaces) | ||
g.Expect(platform).To(Equal(test.expectedPlatform)) | ||
}) | ||
} | ||
} |