-
Notifications
You must be signed in to change notification settings - Fork 0
Test/cmd initial #18
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
Merged
Test/cmd initial #18
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
998c1c1
test: expired cert case for certinfo
xenOs76 6431bfd
test: cmd files
xenOs76 659f2f9
ci: move to go 1.25
xenOs76 3e1e77f
test: add test coverage settings
xenOs76 946eb30
ci: remove tests for go 1.24
xenOs76 cd3e342
ci: add test coverage check
xenOs76 88b4642
ci: update go test coverage check settings
xenOs76 a4f7af6
ci: lower test coverage limit
xenOs76 c901bba
ci: trigger CI when test coverage setting change
xenOs76 60a63ad
ci: exclude files from test coverage
xenOs76 d5d3e22
ci: run go_test_coverage after go_tests
xenOs76 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| profile: cover.out | ||
|
|
||
| threshold: | ||
| file: 70 | ||
| package: 80 | ||
| total: 80 | ||
|
|
||
| exclude: | ||
| paths: | ||
| - internal/style/style_handlers.go | ||
| - main\.go$ | ||
| - cmd/main\.go$ |
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,124 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| _ "embed" | ||
| "testing" | ||
|
|
||
| _ "github.com/breml/rootcerts" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCertinfoCmd(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| args []string | ||
| expectError bool | ||
| errMsgs []string | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "no args", | ||
| args: []string{"certinfo"}, | ||
| expectError: false, | ||
| expected: []string{ | ||
| "https-wrench certinfo", | ||
| "Usage:", | ||
| "Flags:", | ||
| "Global Flags:", | ||
| "--key-file", | ||
| "--tls-endpoint", | ||
| "--tls-insecure", | ||
| "--tls-servername", | ||
| "--ca-bundle", | ||
| "--version", | ||
| "--help", | ||
| }, | ||
| }, | ||
| { | ||
| name: "key-file flag no value", | ||
| args: []string{"certinfo", "--key-file"}, | ||
| expectError: true, | ||
| errMsgs: []string{ | ||
| "flag needs an argument: --key-file", | ||
| }, | ||
| expected: []string{ | ||
| "https-wrench certinfo [flags]", | ||
| "--ca-bundle string", | ||
| "--key-file string", | ||
| "--tls-endpoint string", | ||
| "--tls-insecure", | ||
| "--tls-servername string", | ||
| "Usage:", | ||
| "--version Display the version", | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "tls-endpoint flag no value", | ||
| args: []string{"certinfo", "--tls-endpoint"}, | ||
| expectError: true, | ||
| errMsgs: []string{ | ||
| "flag needs an argument: --tls-endpoint", | ||
| }, | ||
| expected: []string{ | ||
| "https-wrench certinfo [flags]", | ||
| "--ca-bundle string", | ||
| "--key-file string", | ||
| "--tls-endpoint string", | ||
| "--tls-insecure", | ||
| "--tls-servername string", | ||
| "Usage:", | ||
| "--version Display the version", | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "tls-insecure incomplete params", | ||
| args: []string{"certinfo", "--tls-insecure"}, | ||
| expectError: false, | ||
| expected: []string{ | ||
| "https-wrench certinfo [flags]", | ||
| "--ca-bundle string", | ||
| "--key-file string", | ||
| "--tls-endpoint string", | ||
| "--tls-insecure", | ||
| "--tls-servername string", | ||
| "Usage:", | ||
| "--version Display the version", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| tt := tc | ||
|
|
||
| t.Run(tt.name, func(t *testing.T) { | ||
| reqOut := new(bytes.Buffer) | ||
| reqCmd := rootCmd | ||
| reqCmd.SetOut(reqOut) | ||
| reqCmd.SetErr(reqOut) | ||
| reqCmd.SetArgs(tt.args) | ||
| err := reqCmd.Execute() | ||
|
|
||
| if tt.expectError { | ||
| require.Error(t, err) | ||
|
|
||
| for _, expected := range tt.errMsgs { | ||
| require.ErrorContains(t, err, expected) | ||
| } | ||
|
|
||
| // return | ||
| } | ||
|
|
||
| if !tt.expectError { | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| got := reqOut.String() | ||
| for _, expexted := range tt.expected { | ||
| require.Contains(t, got, expexted) | ||
| } | ||
| }) | ||
| } | ||
| } |
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,32 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "testing" | ||
|
|
||
| _ "github.com/breml/rootcerts" | ||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/xenos76/https-wrench/internal/requests" | ||
| ) | ||
|
|
||
| var emptyString = "" | ||
|
|
||
| func TestNewHTTPSWrenchConfig(t *testing.T) { | ||
| t.Run("new HTTPSWrenchConfig", func(t *testing.T) { | ||
| var mc requests.RequestsMetaConfig | ||
|
|
||
| config := NewHTTPSWrenchConfig() | ||
|
|
||
| require.False(t, config.Debug) | ||
| require.False(t, config.Verbose) | ||
| require.Equal(t, config.CaBundle, emptyString) | ||
|
|
||
| if diff := cmp.Diff(mc, config.RequestsMetaConfig); diff != "" { | ||
| t.Errorf( | ||
| "NewHTTPSWrenchConfig: RequestsMetaConfig mismatch (-want +got):\n%s", | ||
| diff, | ||
| ) | ||
| } | ||
| }) | ||
| } |
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,141 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| _ "embed" | ||
| "testing" | ||
|
|
||
| _ "github.com/breml/rootcerts" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRequestsCmd(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| args []string | ||
| expectError bool | ||
| errMsgs []string | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "no args", | ||
| args: []string{"requests"}, | ||
| expectError: false, | ||
| expected: []string{ | ||
| "https-wrench requests", | ||
| "Usage:", | ||
| "Flags:", | ||
| "Global Flags:", | ||
| "--config", | ||
| "--ca-bundle", | ||
| "--show-sample-config", | ||
| "--version", | ||
| "--help", | ||
| }, | ||
| }, | ||
| { | ||
| name: "show sample config", | ||
| args: []string{"requests", "--show-sample-config"}, | ||
| expectError: false, | ||
| expected: []string{ | ||
| "https-wrench.schema.json", | ||
| "requests:", | ||
| "transportOverrideUrl:", | ||
| "requestHeaders:", | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "ca-bundle flag no value", | ||
| args: []string{"requests", "--ca-bundle"}, | ||
| expectError: true, | ||
| errMsgs: []string{ | ||
| "flag needs an argument: --ca-bundle", | ||
| }, | ||
| expected: []string{ | ||
| "https-wrench requests [flags]", | ||
| "--ca-bundle string", | ||
| "Usage:", | ||
| "--version Display the version", | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| name: "config flag no file", | ||
| args: []string{"requests", "--config"}, | ||
| expectError: true, | ||
| errMsgs: []string{ | ||
| "flag needs an argument: --config", | ||
| }, | ||
| expected: []string{ | ||
| "https-wrench requests [flags]", | ||
| "--ca-bundle string", | ||
| "Usage:", | ||
| "--version Display the version", | ||
| }, | ||
| }, | ||
|
|
||
| // WARN conflicts with same test for rootCmd | ||
| // { | ||
| // name: "config flag file not exist", | ||
| // args: []string{ | ||
| // "requests", | ||
| // "--config", | ||
| // "/not-existent-file", | ||
| // }, | ||
| // expectError: false, | ||
| // expected: []string{ | ||
| // "Config file not found:", | ||
| // "https-wrench requests [flags]", | ||
| // "--ca-bundle string", | ||
| // "Usage:", | ||
| // "--version Display the version", | ||
| // }, | ||
| // }, | ||
| // | ||
| // WARN conflicts with same test for rootCmd | ||
| // { | ||
| // name: "version", | ||
| // args: []string{"requests", "--version"}, | ||
| // expectError: false, | ||
| // expected: []string{ | ||
| // "https-wrench requests [flags]", | ||
| // "--ca-bundle string", | ||
| // "Usage:", | ||
| // "--version Display the version", | ||
| // }, | ||
| // }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| tt := tc | ||
|
|
||
| t.Run(tt.name, func(t *testing.T) { | ||
| reqOut := new(bytes.Buffer) | ||
| reqCmd := rootCmd | ||
| reqCmd.SetOut(reqOut) | ||
| reqCmd.SetErr(reqOut) | ||
| reqCmd.SetArgs(tt.args) | ||
| err := reqCmd.Execute() | ||
|
|
||
| if tt.expectError { | ||
| require.Error(t, err) | ||
|
|
||
| for _, expected := range tt.errMsgs { | ||
| require.ErrorContains(t, err, expected) | ||
| } | ||
|
|
||
| // return | ||
| } | ||
|
|
||
| if !tt.expectError { | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| got := reqOut.String() | ||
| for _, expexted := range tt.expected { | ||
| require.Contains(t, got, expexted) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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.
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.
Typo:
expexted→expected.Fix typo
🤖 Prompt for AI Agents