File: main_test.go

package info (click to toggle)
dmarc-cat 0.9.2-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 164 kB
  • sloc: xml: 104; makefile: 27
file content (79 lines) | stat: -rw-r--r-- 1,453 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

import (
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSetup(t *testing.T) {
	ctx := Setup([]string{})
	assert.Nil(t, ctx)
}

func TestSetup2(t *testing.T) {
	ctx := Setup([]string{"foo.zip"})
	assert.NotNil(t, ctx)
	assert.IsType(t, (*Context)(nil), ctx)
}

func TestSetup3(t *testing.T) {
	fNoResolv = true
	ctx := Setup([]string{"foo.zip"})
	assert.NotNil(t, ctx)
	assert.IsType(t, (*Context)(nil), ctx)
	fNoResolv = false
}

func TestSetup4(t *testing.T) {
	fVersion = true
	ctx := Setup([]string{"foo.zip"})
	assert.Nil(t, ctx)
	fVersion = false
}

func TestVersion(t *testing.T) {
	Version()
}

// XXX I'm not sure how to really test main() — os.Args() is global and not reset between calls

func TestMain_Noargs(t *testing.T) {
	main()
}

func TestMain_Noargs_Verbose(t *testing.T) {
	fVerbose = true
	main()
	fVerbose = false
}

func TestMain_Noargs_Debug(t *testing.T) {
	fDebug = true
	main()
	fDebug = false
}

func TestMain_Noargs_NoResolv(t *testing.T) {
	os.Args = append(os.Args, "testdata/google.com!keltia.net!1538438400!1538524799.zip")

	fNoResolv = true
	main()
	fNoResolv = false
}

func TestMain_GoodFile(t *testing.T) {
	os.Args = append(os.Args, "testdata/google.com!keltia.net!1538438400!1538524799.zip")
	main()
}

func TestMain_NoFile(t *testing.T) {
	os.Args = append(os.Args, "/nonexistent")
	main()
}

func TestMain_EmptyArg(t *testing.T) {
	os.Args = append(os.Args, "foo")
	main()
}