Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/codeChecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- ".github/workflows/codeChecks.yml"
- ".goreleaser.yaml"
- ".testcoverage.yml"
- "devenv.*"
- "cmd/**"
- "internal/**"
Expand All @@ -13,13 +14,12 @@ on:
- "go.*"

jobs:

go_tests:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
go-version: ['1.24', '1.25']
go-version: ["1.25"]

steps:
- name: Checkout
Expand Down Expand Up @@ -69,6 +69,23 @@ jobs:
run: devenv test
timeout-minutes: 15

go_test_coverage_check:
needs: go_tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: "1.25"

- name: generate test coverage
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...

- name: check test coverage
uses: vladopajic/go-test-coverage@v2
with:
config: ./.testcoverage.yml

goreleaser_test:
needs: devenv_test
runs-on: ubuntu-latest
Expand All @@ -85,7 +102,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version: "1.25"

- name: Run GoReleaser test
uses: goreleaser/goreleaser-action@v6
Expand Down
12 changes: 12 additions & 0 deletions .testcoverage.yml
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$
124 changes: 124 additions & 0 deletions cmd/certinfo_test.go
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)
}
})
}
}
32 changes: 32 additions & 0 deletions cmd/config_test.go
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,
)
}
})
}
4 changes: 2 additions & 2 deletions cmd/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ Examples:
versionRequested := viper.GetBool("version")

if versionRequested {
fmt.Print(version)
cmd.Print(version)
return
}

if showSampleConfig {
fmt.Print(sampleYamlConfig)
cmd.Print(sampleYamlConfig)
return
}

Expand Down
141 changes: 141 additions & 0 deletions cmd/requests_test.go
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 {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo: expextedexpected.

Fix typo
-			for _, expexted := range tt.expected {
-				require.Contains(t, got, expexted)
+			for _, expected := range tt.expected {
+				require.Contains(t, got, expected)
🤖 Prompt for AI Agents
In @cmd/requests_test.go at line 136, There is a typo in the test loop variable
name: change the misspelled variable "expexted" to "expected" in the for loop
(the loop declaration that reads "for _, expexted := range tt.expected {");
update any subsequent references within that loop body to use "expected" so the
variable name is consistent.

require.Contains(t, got, expexted)
}
})
}
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ https://github.com/xenOs76/https-wrench`,
Run: func(cmd *cobra.Command, args []string) {
showVersion, _ := cmd.Flags().GetBool("version")
if showVersion {
fmt.Println(version)
cmd.Println(version)

return
}
Expand Down
Loading
Loading