-
Notifications
You must be signed in to change notification settings - Fork 20
Increasing coverage and simplifying coverage report creation. #3103
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
Open
davidadas
wants to merge
2
commits into
confluentinc:main
Choose a base branch
from
davidadas:coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -96,12 +96,12 @@ cmd/lint/en_US.dic: | |
|
|
||
| .PHONY: unit-test | ||
| unit-test: | ||
| ifdef CI | ||
| go install gotest.tools/[email protected] && \ | ||
| gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v -race -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) | ||
| else | ||
| go test -timeout 0 -v -coverprofile=coverage.unit.out -covermode=atomic $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) $(UNIT_TEST_ARGS) | ||
| endif | ||
| @if [ ! -f "$(shell go env GOPATH)/bin/gotestsum$(shell go env GOEXE)" ]; then \ | ||
| go install gotest.tools/[email protected] ; \ | ||
| fi | ||
| @"$(shell go env GOPATH)/bin/gotestsum$(shell go env GOEXE)" --junitfile unit-test-report.xml -- \ | ||
| -timeout 0 -v -race -coverprofile=coverage.unit.out -covermode=atomic \ | ||
| $$(go list ./... | grep -v github.com/confluentinc/cli/v4/test) | ||
|
|
||
| .PHONY: build-for-integration-test | ||
| build-for-integration-test: | ||
|
|
@@ -121,18 +121,14 @@ endif | |
|
|
||
| .PHONY: integration-test | ||
| integration-test: | ||
| ifdef CI | ||
| go install gotest.tools/[email protected] && \ | ||
| export GOCOVERDIR=test/coverage && \ | ||
| rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \ | ||
| gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v4/test) && \ | ||
| go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out | ||
| else | ||
| export GOCOVERDIR=test/coverage && \ | ||
| rm -rf $${GOCOVERDIR} && mkdir $${GOCOVERDIR} && \ | ||
| go test -timeout 0 -v $$(go list ./... | grep github.com/confluentinc/cli/v4/test) $(INTEGRATION_TEST_ARGS) && \ | ||
| go tool covdata textfmt -i $${GOCOVERDIR} -o coverage.integration.out | ||
| endif | ||
| @if [ ! -f "$(shell go env GOPATH)/bin/gotestsum$(shell go env GOEXE)" ]; then \ | ||
| go install gotest.tools/[email protected] ; \ | ||
| fi | ||
| @rm -rf test/coverage && mkdir -p test/coverage && \ | ||
| GOCOVERDIR=test/coverage "$(shell go env GOPATH)/bin/gotestsum$(shell go env GOEXE)" --junitfile integration-test-report.xml -- \ | ||
| -timeout 0 -v -race $$(go list ./... | grep github.com/confluentinc/cli/v4/test) && \ | ||
| go tool covdata textfmt -i test/coverage -o coverage.integration.out | ||
|
|
||
|
|
||
| .PHONY: test | ||
| test: unit-test integration-test | ||
|
|
@@ -142,10 +138,17 @@ generate-packaging-patch: | |
| diff -u Makefile debian/Makefile | sed "1 s_Makefile_cli/Makefile_" > debian/patches/standard_build_layout.patch | ||
|
|
||
| .PHONY: coverage | ||
| coverage: ## Merge coverage data from unit and integration tests into coverage.txt | ||
| coverage: | ||
| @echo "Merging coverage data..." | ||
| @echo "mode: atomic" > coverage.txt | ||
| @tail -n +2 coverage.unit.out >> coverage.txt | ||
| @tail -n +2 coverage.integration.out >> coverage.txt | ||
| @echo "mode: atomic" > coverage.out | ||
| @tail -n +2 coverage.unit.out >> coverage.out || echo "No unit coverage found" | ||
| @tail -n +2 coverage.integration.out >> coverage.out || echo "No integration coverage found" | ||
|
|
||
| ifeq ($(CI),true) | ||
| @cp coverage.out coverage.txt | ||
| @echo "Coverage data saved to: coverage.txt" | ||
| @artifact push workflow coverage.txt | ||
| @artifact push workflow coverage.txt | ||
| else | ||
| @go tool cover -func=coverage.out | ||
| @go tool cover -html=coverage.out -o coverage.html | ||
| endif | ||
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 |
|---|---|---|
|
|
@@ -3,8 +3,9 @@ package byok | |
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| byokv1 "github.com/confluentinc/ccloud-sdk-go-v2/byok/v1" | ||
| ) | ||
|
|
||
| func TestRemoveKeyVersionFromAzureKeyId(t *testing.T) { | ||
|
|
@@ -44,30 +45,113 @@ func TestRemoveKeyVersionFromAzureKeyId(t *testing.T) { | |
| } | ||
|
|
||
| func TestGcpMetadataCustomRoleName(t *testing.T) { | ||
| t.Run("success, custom role name generated", func(t *testing.T) { | ||
| metadata := gcpPolicyMetadata{ | ||
| keyRing: "testKeyRing", | ||
| key: "testKey", | ||
| } | ||
| customRoleName := metadata.getCustomRoleName() | ||
| assert.Equal(t, "testKeyRing_testKey_custom_kms_role", customRoleName) | ||
| }) | ||
| tests := []struct { | ||
| name string | ||
| keyRing string | ||
| key string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "success, custom role name generated", | ||
| keyRing: "testKeyRing", | ||
| key: "testKey", | ||
| expected: "testKeyRing_testKey_custom_kms_role", | ||
| }, | ||
| { | ||
| name: "success, hyphens replaced", | ||
| keyRing: "test-key-ring", | ||
| key: "test-key", | ||
| expected: "test_key_ring_test_key_custom_kms_role", | ||
| }, | ||
| { | ||
| name: "failure, unsupported characters return default", | ||
| keyRing: "test&key&ring", | ||
| key: "test&key", | ||
| expected: "custom_kms_role", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| metadata := gcpPolicyMetadata{ | ||
| keyRing: test.keyRing, | ||
| key: test.key, | ||
| } | ||
| actual := metadata.getCustomRoleName() | ||
| require.Equal(t, test.expected, actual) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| t.Run("success, hyphens replaced", func(t *testing.T) { | ||
| metadata := gcpPolicyMetadata{ | ||
| keyRing: "test-key-ring", | ||
| key: "test-key", | ||
| } | ||
| customRoleName := metadata.getCustomRoleName() | ||
| assert.Equal(t, "test_key_ring_test_key_custom_kms_role", customRoleName) | ||
| }) | ||
| func TestGetPolicyCommand(t *testing.T) { | ||
| awsRoles := []string{"arn:aws:iam::123456789012:role/test-role"} | ||
| azureKeyID := "https://vault-name.vault.azure.net/keys/key-name" | ||
| azureAppID := "00000000-0000-0000-0000-000000000000" | ||
| gcpKeyID := "projects/proj/locations/loc/keyRings/ring/cryptoKeys/key/cryptoKeyVersions/1" | ||
| gcpGroup := "[email protected]" | ||
|
|
||
| t.Run("failure, default role name returned", func(t *testing.T) { | ||
| metadata := gcpPolicyMetadata{ | ||
| keyRing: "test&key&ring", | ||
| key: "test&key", | ||
| } | ||
| customRoleName := metadata.getCustomRoleName() | ||
| assert.Equal(t, "custom_kms_role", customRoleName) | ||
| }) | ||
| tests := []struct { | ||
| name string | ||
| key byokv1.ByokV1Key | ||
| wantErr bool | ||
| contains string | ||
| }{ | ||
| { | ||
| name: "aws with valid role", | ||
| key: byokv1.ByokV1Key{ | ||
| Key: &byokv1.ByokV1KeyKeyOneOf{ | ||
| ByokV1AwsKey: &byokv1.ByokV1AwsKey{ | ||
| Roles: &awsRoles, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| contains: "arn:aws:iam", | ||
| }, | ||
| { | ||
| name: "azure with valid input", | ||
| key: byokv1.ByokV1Key{ | ||
| Key: &byokv1.ByokV1KeyKeyOneOf{ | ||
| ByokV1AzureKey: &byokv1.ByokV1AzureKey{ | ||
| KeyId: azureKeyID, | ||
| ApplicationId: &azureAppID, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| contains: "az role assignment create", | ||
| }, | ||
| { | ||
| name: "gcp with valid key", | ||
| key: byokv1.ByokV1Key{ | ||
| Key: &byokv1.ByokV1KeyKeyOneOf{ | ||
| ByokV1GcpKey: &byokv1.ByokV1GcpKey{ | ||
| KeyId: gcpKeyID, | ||
| SecurityGroup: &gcpGroup, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: false, | ||
| contains: "[email protected]", | ||
| }, | ||
|
|
||
| { | ||
| name: "unknown key type returns empty string", | ||
| key: byokv1.ByokV1Key{Key: &byokv1.ByokV1KeyKeyOneOf{}}, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| actual, err := getPolicyCommand(test.key) | ||
| if test.wantErr { | ||
| require.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| if test.contains != "" { | ||
| require.Contains(t, actual, test.contains) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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
|
Member
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. This file looks unused; can we remove it? |
Empty file.
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,4 @@ | ||
| Error: accepts 1 arg(s), received 0 | ||
|
|
||
| Suggestions: | ||
| Please run "confluent flink endpoint list" to see all available Flink endpoints, or "confluent flink region use" to switch to a different cloud or region. |
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,4 @@ | ||
| Error: Current Flink cloud provider is empty | ||
|
|
||
| Suggestions: | ||
| Please run `confluent flink region use --cloud <cloud> --region <region>` to set the Flink cloud provider first. |
|
Member
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. This file also looks unused. |
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,6 @@ | ||
| error: coverage meta-data emit failed: output directory "/test/coverage" inaccessible (err: stat /test/coverage: no such file or directory); no coverage data written | ||
| Error: Current Flink cloud provider is empty | ||
|
|
||
| Suggestions: | ||
| Please run confluent flink region use --cloud <cloud> --region <region> to set the Flink cloud provider first. | ||
| error: coverage counter data emit failed: output directory "/test/coverage" inaccessible (err: stat /test/coverage: no such file or directory); no coverage data written |
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 @@ | ||
| Unset the current Flink region |
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
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.
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.
We'll want to put this above line 15 because everything below that is managed by automation, which will probably revert this.