Skip to content
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

Add Test for GetUnusedAll functionality #165

Open
yonahd opened this issue Nov 22, 2023 · 0 comments
Open

Add Test for GetUnusedAll functionality #165

yonahd opened this issue Nov 22, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@yonahd
Copy link
Owner

yonahd commented Nov 22, 2023

In order to properly support testing this we need to refactor the tests in the rest of the resources by separating creating the clientset from the resource creation e.g. deployments

func createTestDeployments(clientset *fake.Clientset, t *testing.T) {
	appLabels := map[string]string{}

	deployment1 := CreateTestDeployment(testNamespace, "test-deployment1", 0, appLabels)
	deployment2 := CreateTestDeployment(testNamespace, "test-deployment2", 1, appLabels)
	_, err := clientset.AppsV1().Deployments(testNamespace).Create(context.TODO(), deployment1, v1.CreateOptions{})
	if err != nil {
		t.Fatalf("Error creating fake deployment: %v", err)
	}

	_, err = clientset.AppsV1().Deployments(testNamespace).Create(context.TODO(), deployment2, v1.CreateOptions{})
	if err != nil {
		t.Fatalf("Error creating fake deployment: %v", err)
	}
}

func createTestDeploymentsClient(t *testing.T) *fake.Clientset {
	clientset := fake.NewSimpleClientset()

	_, err := clientset.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
		ObjectMeta: v1.ObjectMeta{Name: testNamespace},
	}, v1.CreateOptions{})

	if err != nil {
		t.Fatalf("Error creating namespace %s: %v", testNamespace, err)
	}

	createTestDeployments(clientset, t)

	return clientset
}

Once this is done the all test can reuse createTestDeployments(and the same for the rest of the resources)

@yonahd yonahd added enhancement New feature or request good first issue Good for newcomers labels Nov 22, 2023
@yonahd yonahd self-assigned this Dec 26, 2023
@yonahd yonahd linked a pull request Dec 27, 2023 that will close this issue
@yonahd yonahd removed their assignment Feb 20, 2024
@yonahd yonahd removed the good first issue Good for newcomers label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant