-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathend_to_end_test.go
108 lines (76 loc) · 2.45 KB
/
end_to_end_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"encoding/json"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEndToEndFunc(t *testing.T) {
os.Setenv("EXECUTION_ENVIRONMENT", "test")
server := HTTPResponseEndToEnd()
defer server.Close()
// reset command line arg
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = append(os.Args, "--orgID=123")
os.Args = append(os.Args, "--token=123")
os.Args = append(os.Args, "--jiraProjectID=123")
os.Args = append(os.Args, "--api="+server.URL)
// Keeping the line below => useful for debug but print too many things
// os.Args = append(os.Args, "-debug=true")
// Get the console output
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
main()
// Test finished, read the output and compare with expectation
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
// Checking the log file
path, found := findLogFile("listOfTicketCreated")
assert.FileExists(t, path)
assert.True(t, found)
// check if the json is valid
file, err := os.ReadFile(path)
if err != nil {
panic(err)
}
var unmarshalledFile interface{}
assert.Equal(t, json.Unmarshal(file, &unmarshalledFile), nil)
// Delete the file created for the test
removeLogFile()
os.Args = oldArgs
compare := strings.Contains(string(out), "Number of tickets created: 3")
assert.Equal(t, compare, true)
}
// comment for now, error with the arguments that are redefined
// Probably need a clear somewhere in the previous TestEndToEndFunc
// func TestEndToEndDryRunFunc(t *testing.T) {
// server := HTTPResponseEndToEnd()
// defer server.Close()
// fmt.Println(os.Args)
// os.Args = append(os.Args, "-orgID=123")
// os.Args = append(os.Args, "-token=123")
// os.Args = append(os.Args, "-jiraProjectID=123")
// os.Args = append(os.Args, "-api="+server.URL)
// os.Args = append(os.Args, "-dryRun=true")
// // Get the console output
// rescueStdout := os.Stdout
// r, w, _ := os.Pipe()
// os.Stdout = w
// main()
// os.Args = []string{}
// // Test finished, read the output and compare with expectation
// w.Close()
// out, _ := ioutil.ReadAll(r)
// os.Stdout = rescueStdout
// compare := strings.Contains(string(out), "Number of tickets created: 0")
// dryRunResult := strings.Contains(string(out), "Dry run result can be found in .log file")
// // Delete the file created for the test
// removeLogFile()
// assert.Equal(t, compare, true)
// assert.Equal(t, dryRunResult, true)
// }