-
Notifications
You must be signed in to change notification settings - Fork 2
Implement unit-tests for the codebase #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b28f5db
b1f649c
ee263e6
7bb7833
29de4ac
33dabbd
d53e7ff
2d9225d
ecb3c62
6d7b09d
6ef2f3e
e124a26
1922e67
2c2bd5c
3170f31
d954b2e
5e2bd87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package crds | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetNICCRDList(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want []Crd | ||
}{ | ||
{ | ||
name: "Correct CRD list", | ||
want: []Crd{ | ||
{ | ||
Resource: "apdoslogconfs", | ||
Group: "appprotectdos.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "apdospolicies", | ||
Group: "appprotectdos.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "dosprotectedresources", | ||
Group: "appprotectdos.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "aplogconfs", | ||
Group: "appprotect.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "appolicies", | ||
Group: "appprotect.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "apusersigs", | ||
Group: "appprotect.f5.com", | ||
Version: "v1beta1", | ||
}, | ||
{ | ||
Resource: "globalconfigurations", | ||
Group: "k8s.nginx.org", | ||
Version: "v1", | ||
}, | ||
{ | ||
Resource: "policies", | ||
Group: "k8s.nginx.org", | ||
Version: "v1", | ||
}, | ||
{ | ||
Resource: "transportservers", | ||
Group: "k8s.nginx.org", | ||
Version: "v1", | ||
}, | ||
{ | ||
Resource: "virtualserverroutes", | ||
Group: "k8s.nginx.org", | ||
Version: "v1", | ||
}, | ||
{ | ||
Resource: "virtualservers", | ||
Group: "k8s.nginx.org", | ||
Version: "v1", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GetNICCRDList(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("GetNICCRDList() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -36,6 +36,7 @@ import ( | |||||
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/crds" | ||||||
"github.com/nginxinc/nginx-k8s-supportpkg/pkg/version" | ||||||
corev1 "k8s.io/api/core/v1" | ||||||
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" | ||||||
crdClient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" | ||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
"k8s.io/apimachinery/pkg/runtime/schema" | ||||||
|
@@ -54,12 +55,14 @@ type DataCollector struct { | |||||
Logger *log.Logger | ||||||
LogFile *os.File | ||||||
K8sRestConfig *rest.Config | ||||||
K8sCoreClientSet *kubernetes.Clientset | ||||||
K8sCrdClientSet *crdClient.Clientset | ||||||
K8sMetricsClientSet *metricsClient.Clientset | ||||||
K8sCoreClientSet kubernetes.Interface | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change from concrete type
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
K8sCrdClientSet apiextensionsclientset.Interface | ||||||
K8sMetricsClientSet metricsClient.Interface | ||||||
K8sHelmClientSet map[string]helmClient.Client | ||||||
ExcludeDBData bool | ||||||
ExcludeTimeSeriesData bool | ||||||
PodExecutor func(namespace, pod, container string, command []string, ctx context.Context) ([]byte, error) | ||||||
QueryCRD func(crd crds.Crd, namespace string, ctx context.Context) ([]byte, error) | ||||||
} | ||||||
|
||||||
type Manifest struct { | ||||||
|
@@ -147,6 +150,8 @@ func NewDataCollector(collector *DataCollector) error { | |||||
collector.LogFile = logFile | ||||||
collector.Logger = log.New(logFile, "", log.LstdFlags|log.LUTC|log.Lmicroseconds|log.Lshortfile) | ||||||
collector.K8sHelmClientSet = make(map[string]helmClient.Client) | ||||||
collector.PodExecutor = collector.RealPodExecutor | ||||||
collector.QueryCRD = collector.RealQueryCRD | ||||||
|
||||||
//Initialize clients | ||||||
collector.K8sRestConfig = config | ||||||
|
@@ -259,7 +264,7 @@ func (c *DataCollector) WrapUp(product string) (string, error) { | |||||
return tarballName, nil | ||||||
} | ||||||
|
||||||
func (c *DataCollector) PodExecutor(namespace string, pod string, container string, command []string, ctx context.Context) ([]byte, error) { | ||||||
func (c *DataCollector) RealPodExecutor(namespace string, pod string, container string, command []string, ctx context.Context) ([]byte, error) { | ||||||
req := c.K8sCoreClientSet.CoreV1().RESTClient().Post(). | ||||||
Namespace(namespace). | ||||||
Resource("pods"). | ||||||
|
@@ -292,7 +297,7 @@ func (c *DataCollector) PodExecutor(namespace string, pod string, container stri | |||||
} | ||||||
} | ||||||
|
||||||
func (c *DataCollector) QueryCRD(crd crds.Crd, namespace string, ctx context.Context) ([]byte, error) { | ||||||
func (c *DataCollector) RealQueryCRD(crd crds.Crd, namespace string, ctx context.Context) ([]byte, error) { | ||||||
|
||||||
schemeGroupVersion := schema.GroupVersion{Group: crd.Group, Version: crd.Version} | ||||||
negotiatedSerializer := scheme.Codecs.WithoutConversion() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the type from *kubernetes.Clientset to kubernetes.Interface is a breaking change that could affect existing code that relies on the concrete type. Consider introducing this change in a separate PR or ensure all dependent code is updated accordingly.
Copilot uses AI. Check for mistakes.