mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Add test for second pass command line passing.
This commit is contained in:
parent
62290215ec
commit
abce4e7f78
2 changed files with 21 additions and 1 deletions
1
internal/options/data/empty.toml
Normal file
1
internal/options/data/empty.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Empty but valid config file
|
||||
|
|
@ -14,7 +14,7 @@ type config struct {
|
|||
ConfigLocation string `long:"configlocation" description:"test location"`
|
||||
}
|
||||
|
||||
// Parser helps parsing command line arguments and loading
|
||||
// TestParse helps parsing command line arguments and loading
|
||||
// stored configurations from file.
|
||||
func TestParse(t *testing.T) {
|
||||
originalArgs := os.Args
|
||||
|
|
@ -152,3 +152,22 @@ func TestErrorCheck(t *testing.T) {
|
|||
t.Fatalf("process ran with err %v, want exit status 1", err)
|
||||
|
||||
}
|
||||
|
||||
// TestSecondPassCommandlineParsing checks if the second pass
|
||||
// of the command line passing is error checked.
|
||||
func TestSecondPassCommandlineParsing(t *testing.T) {
|
||||
orig := os.Args
|
||||
defer func() { os.Args = orig }()
|
||||
|
||||
os.Args = []string{"cmd"}
|
||||
p := Parser[config]{
|
||||
ConfigLocation: func(cfg *config) string {
|
||||
// This is a bit stupid.
|
||||
os.Args = []string{"cmd", "--invalid"}
|
||||
return "data/empty.toml"
|
||||
},
|
||||
}
|
||||
if _, _, err := p.Parse(); err == nil {
|
||||
t.Fatalf("Second command line parsing pass did not fail.\n")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue