-
Notifications
You must be signed in to change notification settings - Fork 57
#704 Add more tests to increase test coverage #755
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
Merged
AzizMukhtorjonov
merged 17 commits into
zigbee-alliance:master
from
Abdulbois:#704-Improve-test-coverage
Jul 6, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cabfac7
Add more tests
Abdulbois 53c72ed
Add extensive negative test cases and remove unused code linters
Abdulbois c7f8615
Fix lint
Abdulbois 971ccd1
Expand test cases for URL liveness and CLI commands, add list upgrade…
Abdulbois 19bf4e4
Improve coverage for URL liveness by merging tests from non-dev build…
Abdulbois 6ca6639
Refactor test coverage workflow: extract unit test script, increase c…
Abdulbois 784ee2c
Enable JSON output and append logs for CLI test coverage in workflow …
Abdulbois dba86a4
Expand test coverage for `UpdatePkiRevocationDistributionPoint` handl…
Abdulbois 0c4d058
Expand test coverage for `CmdListCertificates` and `CmdListAllCertifi…
Abdulbois 82b05e5
Expand test coverage for `MsgProposeUpgrade` and `AddX509Cert` handle…
Abdulbois 9033522
Expand test coverage for PKI handlers with additional edge and negati…
Abdulbois d554e04
Clean-up
Abdulbois d4a16b3
Expand test coverage for `MsgProposeUpgrade`, `MsgAssignVid`, `AddX50…
Abdulbois fe60b10
Expand test coverage for `VerifyVVSCCertificate` with edge and negati…
Abdulbois 4f270c3
Update error handling for unauthorized certificate issuers in PKI han…
Abdulbois a2405a8
Remove redundant test `TestHandler_UpdatePkiRevocationDistributionPoi…
Abdulbois f01969f
Introduce `ErrVVSCChainVerificationFailed` for specific error handlin…
Abdulbois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,5 @@ | |
|
|
||
| profile: 'cover.out' | ||
| threshold: | ||
| total: 50 | ||
| total: 90 | ||
| file: 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Runs the Go unit tests with coverage and writes the merged profile to cover.out. | ||
| # | ||
| # The main suite runs with -tags=dev. url_liveness.go gates its HTTP logic behind | ||
| # that dev flag (and its !dev-tagged test is excluded), so it is unreachable in the | ||
| # dev run. We re-run the utils/cli package without the dev tag to collect real | ||
| # coverage for the liveness checks and merge it in, so it shows up in the coverage | ||
| # report. The non-dev package build reports the same canonical file paths as the | ||
| # dev run, so gocovmerge unions the two cleanly. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| GOCOVMERGE_VERSION="b5bfa59ec0adc420475f97f89b58045c721d761c" | ||
|
|
||
| # shellcheck disable=SC2046 | ||
| go test -tags=dev -json -v $(go list ./... | grep -v '/integration_tests') \ | ||
| -coverprofile=./cover.out -covermode=set -coverpkg=./... 2>&1 \ | ||
| | tee /tmp/gotest.log | gotestfmt | ||
|
|
||
| go test -json -v -covermode=set -coverprofile=./cover_url_liveness.out \ | ||
| -coverpkg=./utils/cli/... ./utils/cli/ 2>&1 \ | ||
| | tee -a /tmp/gotest.log | gotestfmt | ||
|
|
||
| go install "github.com/wadey/gocovmerge@${GOCOVMERGE_VERSION}" | ||
| gocovmerge ./cover.out ./cover_url_liveness.out > ./cover_merged.out | ||
| mv ./cover_merged.out ./cover.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright 2020 DSR Corporation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package cli | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestReadFromFileExistingFile(t *testing.T) { | ||
| const content = "certificate-content\nmultiple-lines\n" | ||
|
|
||
| path := filepath.Join(t.TempDir(), "cert.pem") | ||
| require.NoError(t, os.WriteFile(path, []byte(content), 0o600)) | ||
|
|
||
| got, err := ReadFromFile(path) | ||
| require.NoError(t, err) | ||
| require.Equal(t, content, got) | ||
| } | ||
|
|
||
| func TestReadFromFileEmptyFile(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "empty.pem") | ||
| require.NoError(t, os.WriteFile(path, []byte{}, 0o600)) | ||
|
|
||
| got, err := ReadFromFile(path) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "", got) | ||
| } | ||
|
|
||
| // TestReadFromFileNotAPath covers the branch where the target does not exist on | ||
| // disk and is therefore returned verbatim (e.g. a PEM string passed inline). | ||
| func TestReadFromFileNotAPath(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| target string | ||
| }{ | ||
| {"inline pem", "-----BEGIN CERTIFICATE-----\nMIIB...\n-----END CERTIFICATE-----"}, | ||
| {"plain string", "not-a-file"}, | ||
| {"empty string", ""}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := ReadFromFile(tt.target) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.target, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestReadFromFileReadError covers the branch where os.Stat succeeds but the | ||
| // subsequent read fails. Pointing at a directory triggers a read error while | ||
| // still passing the existence check. | ||
| func TestReadFromFileReadError(t *testing.T) { | ||
| dir := t.TempDir() | ||
|
|
||
| got, err := ReadFromFile(dir) | ||
| require.Error(t, err) | ||
| require.Equal(t, "", got) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.