mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 19:13:06 +00:00
🚨 Update test
This commit is contained in:
parent
3368cc0d10
commit
2478398b3b
@ -24,6 +24,8 @@ 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:
|
||||||
|
@ -42,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: stringPtr("POST"),
|
Method: toPtr("POST"),
|
||||||
URL: &types.RequestURL{},
|
URL: &types.RequestURL{},
|
||||||
DodosCount: uintPtr(10),
|
DodosCount: toPtr[uint](10),
|
||||||
RequestCount: uintPtr(1000),
|
RequestCount: toPtr[uint](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: boolPtr(true),
|
Yes: toPtr(true),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -60,10 +60,6 @@ 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
|
||||||
@ -85,9 +81,6 @@ 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 {
|
||||||
@ -126,9 +119,6 @@ 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
|
||||||
@ -168,14 +158,6 @@ func TestCLIYesOrNoReaderBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper types and functions for testing
|
// Helper types and functions for testing
|
||||||
func stringPtr(s string) *string {
|
func toPtr[T any](value T) *T {
|
||||||
return &s
|
return &value
|
||||||
}
|
|
||||||
|
|
||||||
func uintPtr(u uint) *uint {
|
|
||||||
return &u
|
|
||||||
}
|
|
||||||
|
|
||||||
func boolPtr(b bool) *bool {
|
|
||||||
return &b
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user