-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
52 lines (42 loc) · 1.38 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
// Copyright 2023 The Fileganizer Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package main
import (
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func captureOutput(f func() error) (string, error) {
orig := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
err := f()
os.Stdout = orig
w.Close()
out, _ := io.ReadAll(r)
return string(out), err
}
func TestFileykjwmwqqjhght(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }() // os.Args is a "global variable", so keep the state from before the test, and restore it after.
os.Args = []string{"./fileganizer", "-c", "testdata/config.ykjwmwqqjhgh.yaml", "-f", "testdata/ykjwmwqqjhgh.txt"}
output, err := captureOutput(func() error {
main()
return nil
})
assert.Nil(t, err)
assert.Equal(t, output, "Invoice Summary\n date: 2014-03-27\n number: 001\n")
}
func TestFileykjwmwqqjhghtEnv(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }() // os.Args is a "global variable", so keep the state from before the test, and restore it after.
os.Setenv("SOMEVAR", "magic")
os.Args = []string{"./fileganizer", "-c", "testdata/config.ykjwmwqqjhghEnv.yaml", "-f", "testdata/ykjwmwqqjhgh.txt"}
output, err := captureOutput(func() error {
main()
return nil
})
assert.Nil(t, err)
assert.Equal(t, output, "Invoice magic Summary\n date: 2014-03-27\n number: 001\n")
}