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
|
package main
import (
"os"
"testing"
"time"
"github.com/adhocore/gronx/pkg/tasker"
)
func TestMustGetOption(t *testing.T) {
old := os.Args
exit = func (code int) {}
t.Run("Main", func(t *testing.T) {
expect := tasker.Option{File: "../../test/taskfile.txt", Out: "../../test/out.txt"}
os.Args = append(old, "-verbose", "-file", expect.File, "-out", expect.Out)
mustParseOption()
if opt.File != expect.File {
t.Errorf("file: expected %v, got %v", opt.File, expect.File)
}
if opt.Out != expect.Out {
t.Errorf("out: expected %v, got %v", opt.Out, expect.Out)
}
t.Run("must parse option", func (t *testing.T) {
os.Args = append(old, "-verbose", "-out", expect.Out)
mustParseOption()
if opt.File != "" {
t.Error("opt.File must be empty "+opt.File)
}
os.Args = append(old, "-verbose", "-file", "invalid", "-out", expect.Out)
mustParseOption()
if opt.File != "invalid" {
t.Error("opt.File must be invalid")
}
})
t.Run("run", func (t *testing.T) {
tick = time.Second
os.Args = append(old, "-verbose", "-file", expect.File, "-out", expect.Out, "-until", "2")
main()
})
os.Args = old
})
}
|