From 93ca54a988bfb6d185cce83ac80d7eca7b4afc68 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Tue, 22 Oct 2024 11:14:26 +1300 Subject: [PATCH] fix(support): add missing host collectors for ParseSupportBundle --- pkg/supportbundle/load_test.go | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pkg/supportbundle/load_test.go diff --git a/pkg/supportbundle/load_test.go b/pkg/supportbundle/load_test.go new file mode 100644 index 000000000..e4d54911e --- /dev/null +++ b/pkg/supportbundle/load_test.go @@ -0,0 +1,94 @@ +package supportbundle + +import ( + "reflect" + "testing" + + troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func Test_ParseSupportBundle(t *testing.T) { + tests := []struct { + name string + doc []byte + followURI bool + want *troubleshootv1beta2.SupportBundle + wantErr bool + }{ + { + name: "Parse Host Collectors", + doc: []byte(` +apiVersion: troubleshoot.sh/v1beta2 +kind: SupportBundle +metadata: + name: test +spec: + hostCollectors: + - hostOS: {} +`), + followURI: false, + want: &troubleshootv1beta2.SupportBundle{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "troubleshoot.sh/v1beta2", + Kind: "SupportBundle", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + }, + Spec: troubleshootv1beta2.SupportBundleSpec{ + HostCollectors: []*troubleshootv1beta2.HostCollect{ + { + HostOS: &troubleshootv1beta2.HostOS{}, + }, + }, + }, + }, + wantErr: false, + }, + { + name: "Parse Collectors", + doc: []byte(` +apiVersion: troubleshoot.sh/v1beta2 +kind: SupportBundle +metadata: + name: test +spec: + collectors: + - clusterInfo: {} +`), + followURI: false, + want: &troubleshootv1beta2.SupportBundle{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "troubleshoot.sh/v1beta2", + Kind: "SupportBundle", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + }, + Spec: troubleshootv1beta2.SupportBundleSpec{ + Collectors: []*troubleshootv1beta2.Collect{ + { + ClusterInfo: &troubleshootv1beta2.ClusterInfo{}, + }, + }, + }, + }, + wantErr: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ParseSupportBundle(tt.doc, tt.followURI) + if (err != nil) != tt.wantErr { + t.Errorf("ParseSupportBundle() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ParseSupportBundle() = %v, want %v", got, tt.want) + } + }) + } +}