Compare commits

...

2 Commits

Author SHA1 Message Date
60efd5980f 🚨 Update test 2025-04-18 20:41:25 +04:00
2478398b3b 🚨 Update test 2025-04-18 15:29:31 +04:00
3 changed files with 13 additions and 32 deletions

View File

@ -24,6 +24,8 @@ tasks:
lint: golangci-lint run
test: go test ./...
build: go build -ldflags "-s -w" -o "dodo"
build-all:

View File

@ -8,6 +8,7 @@ import (
"time"
"github.com/aykhans/dodo/types"
"github.com/aykhans/dodo/utils"
"github.com/stretchr/testify/assert"
)
@ -42,13 +43,13 @@ func TestReadCLI(t *testing.T) {
expectFile: "/path/to/config.json",
expectError: false,
expectedConfig: &Config{
Method: stringPtr("POST"),
Method: utils.ToPtr("POST"),
URL: &types.RequestURL{},
DodosCount: uintPtr(10),
RequestCount: uintPtr(1000),
DodosCount: utils.ToPtr[uint](10),
RequestCount: utils.ToPtr[uint](1000),
Duration: &types.Duration{Duration: 3 * time.Minute},
Timeout: &types.Timeout{Duration: 3 * time.Second},
Yes: boolPtr(true),
Yes: utils.ToPtr(true),
},
},
{
@ -60,10 +61,6 @@ func TestReadCLI(t *testing.T) {
},
}
// Save original command-line arguments
origArgs := os.Args
origFlagCommandLine := flag.CommandLine
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Reset flag.CommandLine to its original state
@ -85,9 +82,6 @@ func TestReadCLI(t *testing.T) {
// Call the function being tested
file, err := config.ReadCLI()
// Reset os.Args after test
os.Args = origArgs
// Assert expected results
assert.Equal(t, tt.expectFile, file)
if tt.expectError {
@ -126,9 +120,6 @@ func TestReadCLI(t *testing.T) {
}
})
}
// Restore original flag.CommandLine
flag.CommandLine = origFlagCommandLine
}
// Skip the prompt tests as they require interactive input/output handling
@ -166,16 +157,3 @@ func TestCLIYesOrNoReaderBasic(t *testing.T) {
// Default value should be returned
assert.True(t, result)
}
// Helper types and functions for testing
func stringPtr(s string) *string {
return &s
}
func uintPtr(u uint) *uint {
return &u
}
func boolPtr(b bool) *bool {
return &b
}

View File

@ -3,6 +3,7 @@ package config
import (
"net/url"
"os"
"slices"
"testing"
"time"
@ -415,11 +416,11 @@ func TestMergeConfig(t *testing.T) {
RequestCount: utils.ToPtr(*baseConfig.RequestCount),
Duration: &types.Duration{Duration: baseConfig.Duration.Duration},
Yes: utils.ToPtr(*baseConfig.Yes),
Params: append(types.Params{}, baseConfig.Params...),
Headers: append(types.Headers{}, baseConfig.Headers...),
Cookies: append(types.Cookies{}, baseConfig.Cookies...),
Body: append(types.Body{}, baseConfig.Body...),
Proxies: append(types.Proxies{}, baseConfig.Proxies...),
Params: slices.Clone(baseConfig.Params),
Headers: slices.Clone(baseConfig.Headers),
Cookies: slices.Clone(baseConfig.Cookies),
Body: slices.Clone(baseConfig.Body),
Proxies: slices.Clone(baseConfig.Proxies),
}
// Call the function being tested