forked from securego/gosec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag_test.go
45 lines (41 loc) · 1.41 KB
/
flag_test.go
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
package gosec_test
import (
"flag"
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/securego/gosec/v2/cmd/vflag"
)
var _ = Describe("Cli", func() {
Context("vflag test", func() {
It("value must be empty as parameter value contains invalid character", func() {
os.Args = []string{"gosec", "-flag1=-incorrect"}
f := vflag.ValidatedFlag{}
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flag.Var(&f, "falg1", "")
flag.CommandLine.Init("flag1", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``))
})
It("value must be empty as parameter value contains invalid character without equal sign", func() {
os.Args = []string{"gosec", "-test2= -incorrect"}
f := vflag.ValidatedFlag{}
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
flag.Var(&f, "test2", "")
flag.CommandLine.Init("test2", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(``))
})
It("value must not be empty as parameter value contains valid character", func() {
os.Args = []string{"gosec", "-test3=correct"}
f := vflag.ValidatedFlag{}
flag.Var(&f, "test3", "")
flag.CommandLine.Init("test3", flag.ContinueOnError)
flag.Parse()
Expect(flag.Parsed()).Should(BeTrue())
Expect(f.Value).Should(Equal(`correct`))
})
})
})