File: main_test.go

package info (click to toggle)
golang-github-adhocore-gronx 1.19.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download | duplicates (2)
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
	})
}