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 unit tests #70

Merged
merged 1 commit into from
Jan 18, 2025
Merged

add unit tests #70

merged 1 commit into from
Jan 18, 2025

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Dec 10, 2024

This PR adds unit tests for at least the low-hanging fruit and enables the tests in CI. I think what I didn't include here already has decent coverage from the e2e tests, but please let me know if I missed something that would be valuable to add unit tests for.

Fixes #41

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 10, 2024
@jackfrancis
Copy link

/assign @elezar
/assign @pohly

Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nojnhuh. I've made a first pass.

I have a few minor questions and comments.

api/example.com/resource/gpu/v1alpha1/api_test.go Outdated Show resolved Hide resolved
api/example.com/resource/gpu/v1alpha1/api_test.go Outdated Show resolved Hide resolved
api/example.com/resource/gpu/v1alpha1/api_test.go Outdated Show resolved Hide resolved
api/example.com/resource/gpu/v1alpha1/sharing_test.go Outdated Show resolved Hide resolved
api/example.com/resource/gpu/v1alpha1/sharing_test.go Outdated Show resolved Hide resolved
"testing"
)

func TestGpuConfigValidate(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test case that is not covered is that if both TimeSlicing and SpacePartitioning are defined, an invalid SpacePartitioning config is ignored.

This might not be intended behaviour, but it may be behaviour that users start to depend on. (although since this is an example driver it's probably not critical) cc @pohly @klueska

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, that seems worth recording in a test, even if just to signal to authors of real drivers that that's something to look out for and potentially not recreate.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2025
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jan 15, 2025

Pushed a merge commit to fix the conflict in case that's easier to review than a rebase, but I'll plan to squash before merging this.

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jan 15, 2025
go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment on the go modules, but otherwise this looks good.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jan 16, 2025

I took the liberty of squashing after addressing the latest round of feedback.

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 16, 2025
Sharing: &GpuSharing{},
},
expected: "unknown GPU sharing strategy: ",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add this test case:

		"unknown GPU sharing strategy": {
			gpuConfig: &GpuConfig{
				Sharing: &GpuSharing{
					Strategy: "unknown",
				},
			},
			expected: errors.New("unknown GPU sharing strategy: unknown"),
		},

BTW, this test case shows that this code is unreachable.

@bart0sh
Copy link
Contributor

bart0sh commented Jan 17, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2025
Copy link
Contributor

@elezar elezar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elezar, nojnhuh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 18, 2025
@k8s-ci-robot k8s-ci-robot merged commit cfe7e11 into kubernetes-sigs:main Jan 18, 2025
6 checks passed
@elezar elezar mentioned this pull request Jan 18, 2025
@nojnhuh nojnhuh deleted the unit-tests branch January 18, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit testing
6 participants