mirror of
https://github.com/aykhans/dodo.git
synced 2025-06-06 13:56:46 +00:00
Compare commits
No commits in common. "60efd5980f5624aee2e240abff61c1904bbdf410" and "3368cc0d10aab50ebe0a02fa018f10721095fc3e" have entirely different histories.
60efd5980f
...
3368cc0d10
@ -24,8 +24,6 @@ tasks:
|
|||||||
|
|
||||||
lint: golangci-lint run
|
lint: golangci-lint run
|
||||||
|
|
||||||
test: go test ./...
|
|
||||||
|
|
||||||
build: go build -ldflags "-s -w" -o "dodo"
|
build: go build -ldflags "-s -w" -o "dodo"
|
||||||
|
|
||||||
build-all:
|
build-all:
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aykhans/dodo/types"
|
"github.com/aykhans/dodo/types"
|
||||||
"github.com/aykhans/dodo/utils"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,13 +42,13 @@ func TestReadCLI(t *testing.T) {
|
|||||||
expectFile: "/path/to/config.json",
|
expectFile: "/path/to/config.json",
|
||||||
expectError: false,
|
expectError: false,
|
||||||
expectedConfig: &Config{
|
expectedConfig: &Config{
|
||||||
Method: utils.ToPtr("POST"),
|
Method: stringPtr("POST"),
|
||||||
URL: &types.RequestURL{},
|
URL: &types.RequestURL{},
|
||||||
DodosCount: utils.ToPtr[uint](10),
|
DodosCount: uintPtr(10),
|
||||||
RequestCount: utils.ToPtr[uint](1000),
|
RequestCount: uintPtr(1000),
|
||||||
Duration: &types.Duration{Duration: 3 * time.Minute},
|
Duration: &types.Duration{Duration: 3 * time.Minute},
|
||||||
Timeout: &types.Timeout{Duration: 3 * time.Second},
|
Timeout: &types.Timeout{Duration: 3 * time.Second},
|
||||||
Yes: utils.ToPtr(true),
|
Yes: boolPtr(true),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -61,6 +60,10 @@ func TestReadCLI(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save original command-line arguments
|
||||||
|
origArgs := os.Args
|
||||||
|
origFlagCommandLine := flag.CommandLine
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// Reset flag.CommandLine to its original state
|
// Reset flag.CommandLine to its original state
|
||||||
@ -82,6 +85,9 @@ func TestReadCLI(t *testing.T) {
|
|||||||
// Call the function being tested
|
// Call the function being tested
|
||||||
file, err := config.ReadCLI()
|
file, err := config.ReadCLI()
|
||||||
|
|
||||||
|
// Reset os.Args after test
|
||||||
|
os.Args = origArgs
|
||||||
|
|
||||||
// Assert expected results
|
// Assert expected results
|
||||||
assert.Equal(t, tt.expectFile, file)
|
assert.Equal(t, tt.expectFile, file)
|
||||||
if tt.expectError {
|
if tt.expectError {
|
||||||
@ -120,6 +126,9 @@ func TestReadCLI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore original flag.CommandLine
|
||||||
|
flag.CommandLine = origFlagCommandLine
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the prompt tests as they require interactive input/output handling
|
// Skip the prompt tests as they require interactive input/output handling
|
||||||
@ -157,3 +166,16 @@ func TestCLIYesOrNoReaderBasic(t *testing.T) {
|
|||||||
// Default value should be returned
|
// Default value should be returned
|
||||||
assert.True(t, result)
|
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
|
||||||
|
}
|
||||||
|
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -416,11 +415,11 @@ func TestMergeConfig(t *testing.T) {
|
|||||||
RequestCount: utils.ToPtr(*baseConfig.RequestCount),
|
RequestCount: utils.ToPtr(*baseConfig.RequestCount),
|
||||||
Duration: &types.Duration{Duration: baseConfig.Duration.Duration},
|
Duration: &types.Duration{Duration: baseConfig.Duration.Duration},
|
||||||
Yes: utils.ToPtr(*baseConfig.Yes),
|
Yes: utils.ToPtr(*baseConfig.Yes),
|
||||||
Params: slices.Clone(baseConfig.Params),
|
Params: append(types.Params{}, baseConfig.Params...),
|
||||||
Headers: slices.Clone(baseConfig.Headers),
|
Headers: append(types.Headers{}, baseConfig.Headers...),
|
||||||
Cookies: slices.Clone(baseConfig.Cookies),
|
Cookies: append(types.Cookies{}, baseConfig.Cookies...),
|
||||||
Body: slices.Clone(baseConfig.Body),
|
Body: append(types.Body{}, baseConfig.Body...),
|
||||||
Proxies: slices.Clone(baseConfig.Proxies),
|
Proxies: append(types.Proxies{}, baseConfig.Proxies...),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the function being tested
|
// Call the function being tested
|
||||||
|
Loading…
x
Reference in New Issue
Block a user