-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
64 lines (52 loc) · 1.19 KB
/
main_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCheckOutput(t *testing.T) {
fh := checkOutput("")
assert.NotEmpty(t, fh)
assert.EqualValues(t, os.Stdout, fh)
}
func TestCheckOutput_1(t *testing.T) {
temp, err := ioutil.TempDir("", "test")
require.NoError(t, err)
defer os.RemoveAll(temp)
fn := path.Join(temp, "foo.out")
fh := checkOutput(fn)
assert.NotEmpty(t, fh)
fi, err := os.Stat(fn)
assert.NoError(t, err)
assert.NotNil(t, fi)
assert.NotEmpty(t, fi)
}
func TestCheckFlags_Empty(t *testing.T) {
err := checkFlags([]string{})
require.Error(t, err)
}
func TestCheckFlags_Nil(t *testing.T) {
err := checkFlags(nil)
require.Error(t, err)
}
func TestCheckFlags_Good(t *testing.T) {
err := checkFlags([]string{"foo"})
require.NoError(t, err)
}
func TestCheckFlags_GoodVerbose(t *testing.T) {
fVerbose = true
err := checkFlags([]string{"foo"})
require.NoError(t, err)
assert.Equal(t, 1, logLevel)
fVerbose = false
}
func TestCheckFlags_GoodDebug(t *testing.T) {
fDebug = true
err := checkFlags([]string{"foo"})
require.NoError(t, err)
assert.Equal(t, 2, logLevel)
fDebug = false
}