cmd_test.TestDiffForSameFileShouldErr   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
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 := createCommand(logger)
15
	assert.NotNil(t, c)
16
17
	err := executeCommand(c, "result.diff", "-f", "testdata/out.txt", "-s", "testdata/out2.txt")
18
	assert.NoError(t, err)
19
20
	// to keep compatibility with other systems open, the language should take care to use the correct newline symbol
21
	newlineSymbol := fmt.Sprintln()
22
23
	expected := "/" + newlineSymbol +
24
		"├── adview" + newlineSymbol +
25
		"├── partners" + newlineSymbol +
26
		"│   └── \x1b[31mterms\x1b[0m\x1b[32m123\x1b[0m" + newlineSymbol +
27
		"└── s"
28
29
	assert.Contains(t, loggerBuffer.String(), expected)
30
}
31
32
func TestNewResultDiffShouldErrWithInvalidFirstFile(t *testing.T) {
33
	logger, _ := test.NewLogger()
34
35
	c := createCommand(logger)
36
	assert.NotNil(t, c)
37
38
	err := executeCommand(c, "result.diff", "-f", "/root/123/bla", "-s", "testdata/out2.txt")
39
	assert.Error(t, err)
40
41
	assert.Contains(t, err.Error(), "/root/123/bla")
42
}
43
44
func TestNewResultDiffShouldErrWithInvalidSecondFile(t *testing.T) {
45
	logger, _ := test.NewLogger()
46
47
	c := createCommand(logger)
48
	assert.NotNil(t, c)
49
50
	err := executeCommand(c, "result.diff", "-f", "testdata/out2.txt", "-s", "/root/123/bla")
51
	assert.Error(t, err)
52
53
	assert.Contains(t, err.Error(), "/root/123/bla")
54
}
55
56
func TestDiffForSameFileShouldErr(t *testing.T) {
57
	logger, _ := test.NewLogger()
58
59
	c := createCommand(logger)
60
	assert.NotNil(t, c)
61
62
	err := executeCommand(c, "result.diff", "-f", "testdata/out.txt", "-s", "testdata/out.txt")
63
	assert.Error(t, err)
64
	assert.Contains(t, err.Error(), "no diffs found")
65
}
66