-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharbiter_test.go
More file actions
60 lines (46 loc) · 1.56 KB
/
Copy patharbiter_test.go
File metadata and controls
60 lines (46 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package arbiter
import (
"os"
"testing"
"github.com/maansaake/arbiter/pkg/module"
modulemock "github.com/maansaake/arbiter/pkg/module/mock"
"github.com/maansaake/arbiter/pkg/subcommand/cli"
)
func TestRun_DurationTooShort(t *testing.T) {
// Save original args and restore after test
origArgs := os.Args
defer func() { os.Args = origArgs }()
// Set args to simulate duration flag less than 1 second
os.Args = []string{"arbiter", "--duration", "0s", cli.FlagsetName}
// Create a dummy module
modules := module.Modules{&modulemock.Module{SetName: "mock"}}
// Run the function and check for the expected error
err := Run(modules, nil)
if err == nil {
t.Fatalf("expected error, got nil")
}
}
func TestRun_ParsingFailed(t *testing.T) {
// Save original args and restore after test
origArgs := os.Args
defer func() { os.Args = origArgs }()
t.Run("empty report path", func(t *testing.T) {
// Set args to simulate duration flag less than 1 second
os.Args = []string{"arbiter", "-d", "1s", "--report-path", "", cli.FlagsetName}
modules := module.Modules{&modulemock.Module{SetName: "mock"}}
err := Run(modules, nil)
if err == nil {
t.Fatalf("expected error, got nil")
}
})
t.Run("report path is a directory", func(t *testing.T) {
// Create a temporary directory to use as the report path
dir := t.TempDir()
os.Args = []string{"arbiter", "-d", "1s", "--report-path", dir, cli.FlagsetName}
modules := module.Modules{&modulemock.Module{SetName: "mock"}}
err := Run(modules, nil)
if err == nil {
t.Fatalf("expected error, got nil")
}
})
}