-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner_test.go
68 lines (53 loc) · 1.25 KB
/
runner_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
package main
import (
"errors"
"fmt"
"testing"
)
type MockFileReader struct {
Content []byte
Err error
}
func (m MockFileReader) ReadFile(path string) ([]byte, error) {
return m.Content, m.Err
}
func TestRunner_Run_NoArgs(t *testing.T) {
runner := Runner{
Arguments: []string{"runner"},
}
_, err := runner.Run(MockFileReader{})
expected := fmt.Errorf("Please provide two JSON files to compare.\n")
if errors.Is(err, expected) {
t.Errorf("Expected %q, but got %q", expected, expected)
}
}
func TestRunner_Run_ValidFiles(t *testing.T) {
mockFileReader := MockFileReader{
Content: []byte(`{"key1": "value1"}`),
Err: nil,
}
runner := Runner{
Arguments: []string{"file1.json", "file2.json"},
}
output, err := runner.Run(mockFileReader)
expected := "No differences found."
if output != expected {
t.Errorf("Expected %q, but got %q", expected, output)
}
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
}
func TestRunner_Run_InvalidFiles(t *testing.T) {
mockFileReader := MockFileReader{
Content: nil,
Err: nil,
}
runner := Runner{
Arguments: []string{"file1.json", "file2.json"},
}
_, err := runner.Run(mockFileReader)
if err == nil {
t.Errorf("Expected error, but got did not get one")
}
}