Passed
Pull Request — master (#73)
by Stefano
02:19
created

pkg/cmd/result_diff_integration_test.go   A

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 36
dl 0
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cmd_test.TestNewResultDiffShouldErrWithInvalidFirstFile 0 11 1
A cmd_test.TestNewResultDiffShouldErrWithInvalidSecondFile 0 11 1
A cmd_test.TestNewResultDiff 0 20 1
1
package cmd_test
2
3
import (
4
	"fmt"
5
	"testing"
6
7
	"github.com/stefanoj3/dirstalk/pkg/common/test"
8
	"github.com/stretchr/testify/assert"
9
)
10
11
func TestNewResultDiff(t *testing.T) {
12
	logger, loggerBuffer := test.NewLogger()
13
14
	c, err := createCommand(logger)
15
	assert.NoError(t, err)
16
	assert.NotNil(t, c)
17
18
	_, _, err = executeCommand(c, "result.diff", "-f", "testdata/out.txt", "-s", "testdata/out2.txt")
19
	assert.NoError(t, err)
20
21
	// to keep compatibility with other systems open, the language should take care to use the correct newline symbol
22
	newlineSymbol := fmt.Sprintln()
23
24
	expected := "/" + newlineSymbol +
25
		"├── adview" + newlineSymbol +
26
		"├── partners" + newlineSymbol +
27
		"│   └── \x1b[31mterms\x1b[0m\x1b[32m123\x1b[0m" + newlineSymbol +
28
		"└── s"
29
30
	assert.Contains(t, loggerBuffer.String(), expected)
31
}
32
33
func TestNewResultDiffShouldErrWithInvalidFirstFile(t *testing.T) {
34
	logger, _ := test.NewLogger()
35
36
	c, err := createCommand(logger)
37
	assert.NoError(t, err)
38
	assert.NotNil(t, c)
39
40
	_, _, err = executeCommand(c, "result.diff", "-f", "/root/123/bla", "-s", "testdata/out2.txt")
41
	assert.Error(t, err)
42
43
	assert.Contains(t, err.Error(), "/root/123/bla")
44
}
45
46
func TestNewResultDiffShouldErrWithInvalidSecondFile(t *testing.T) {
47
	logger, _ := test.NewLogger()
48
49
	c, err := createCommand(logger)
50
	assert.NoError(t, err)
51
	assert.NotNil(t, c)
52
53
	_, _, err = executeCommand(c, "result.diff", "-f", "testdata/out2.txt", "-s", "/root/123/bla")
54
	assert.Error(t, err)
55
56
	assert.Contains(t, err.Error(), "/root/123/bla")
57
}
58