Skip to content

Increase Unit Test Coverage#54

Merged
ChristianAtDell merged 58 commits into
pub/ut-intermediatefrom
pub/add-unit-tests
Feb 17, 2025
Merged

Increase Unit Test Coverage#54
ChristianAtDell merged 58 commits into
pub/ut-intermediatefrom
pub/add-unit-tests

Conversation

@ChristianAtDell

Copy link
Copy Markdown

Description

This PR includes substantial unit test coverage increase across gocsi packages.

GitHub Issues

List the GitHub issues impacted by this PR:

GitHub Issue #
https://github.com/dell/csm/issues/1707

Checklist:

  • I have performed a self-review of my own code to ensure there are no formatting, vetting, linting, or security issues
  • I have verified that new and existing unit tests pass locally with my changes
  • I have not allowed coverage numbers to degenerate
  • I have maintained at least 80% code coverage
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Backward compatibility is not broken

How Has This Been Tested?

opensuse154:~/git/gocsi # go test -cover -race ./...
?       github.com/dell/gocsi/middleware/serialvolume/types     [no test files]
        github.com/dell/gocsi/mock/provider             coverage: 0.0% of statements
        github.com/dell/gocsi/mock              coverage: 0.0% of statements
        github.com/dell/gocsi/mock/service              coverage: 0.0% of statements
ok      github.com/dell/gocsi   6.100s  coverage: 80.3% of statements
ok      github.com/dell/gocsi/context   1.055s  coverage: 82.1% of statements
ok      github.com/dell/gocsi/csc       1.029s
ok      github.com/dell/gocsi/csc/cmd   1.111s  coverage: 82.2% of statements
ok      github.com/dell/gocsi/middleware/logging        1.075s  coverage: 82.4% of statements
ok      github.com/dell/gocsi/middleware/requestid      1.092s  coverage: 82.8% of statements
ok      github.com/dell/gocsi/middleware/serialvolume   1.080s  coverage: 91.9% of statements
ok      github.com/dell/gocsi/middleware/serialvolume/etcd      9.454s  coverage: 80.3% of statements
ok      github.com/dell/gocsi/middleware/specvalidator  1.084s  coverage: 80.7% of statements
ok      github.com/dell/gocsi/testing   40.879s coverage: [no statements]
ok      github.com/dell/gocsi/utils     1.254s  coverage: 80.4% of statements

The only packages not at 80% or above are:

  • middleware/serialvolume/types (no functional code, only type definitions)
  • mock, mock/service, mock/provider (mock controller client/server, for testing)
  • testing (legacy gomega unit tests)

All other packages are at 80% coverage or above.

alikdell
alikdell previously approved these changes Feb 14, 2025
Comment thread middleware/serialvolume/types/volume_lock_provider.go Outdated
Comment on lines +26 to +29
// if CTX has this key, we want to return error for UT
if ctx.Value(ContextKey("returnError")) == "true" {
return nil, status.Error(codes.InvalidArgument, "Returned error from mock CreateVolume")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it really needed? You can induce an error by passing a bad req, e.g. req.Name longer than 128 characters.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is in the mock, not the driver code; I don't see a problem with having a ctx variable for returning an error, though there are potentially more elegant ways to go about it. I will see if I can find a way to inject this error otherwise and ask @JacobGros since he designed the test.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I decided on a uniform approach for forcing errors in the mocks. Some CSI requests (like ControllerGetCapabilities) do not have any parameters, others would require a different parameter configuration to get the error to return. By setting it in the context, we have an approach that works for all mock CSI calls

Comment thread mock/service/node.go Outdated
@ChristianAtDell ChristianAtDell changed the base branch from main to pub/ut-intermediate February 17, 2025 22:45
@ChristianAtDell ChristianAtDell merged commit f9e7c28 into pub/ut-intermediate Feb 17, 2025
@ChristianAtDell ChristianAtDell deleted the pub/add-unit-tests branch February 17, 2025 22:46
@ChristianAtDell ChristianAtDell mentioned this pull request Feb 17, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants