Passed
Push — master ( 7fc31c...e5d363 )
by Igor
04:51 queued 02:47
created

application.TestExecute_ValidArguments_NoError   B

Complexity

Conditions 3

Size

Total Lines 69
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 44
nop 1
dl 0
loc 69
rs 8.824
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
package application
2
3
import (
4
	"testing"
5
6
	"github.com/stretchr/testify/assert"
7
)
8
9
const (
10
	testSpecificationURL = "./../../test/resources/openapi-files/ValueGeneration.yaml"
11
	testConfigFilename   = "./../../test/resources/config.yaml"
12
)
13
14
func TestExecute_ValidArguments_NoError(t *testing.T) {
15
	tests := []struct {
16
		name      string
17
		arguments []string
18
	}{
19
		{
20
			"serve command with short url",
21
			[]string{
22
				"serve",
23
				"-u",
24
				testSpecificationURL,
25
			},
26
		},
27
		{
28
			"serve command with long url",
29
			[]string{
30
				"serve",
31
				"--specification-url",
32
				testSpecificationURL,
33
			},
34
		},
35
		{
36
			"serve command with url from config (short)",
37
			[]string{
38
				"serve",
39
				"-c",
40
				testConfigFilename,
41
			},
42
		},
43
		{
44
			"serve command with url from config (long)",
45
			[]string{
46
				"serve",
47
				"--configuration",
48
				testConfigFilename,
49
			},
50
		},
51
		{
52
			"validate command with short url",
53
			[]string{
54
				"validate",
55
				"-u",
56
				testSpecificationURL,
57
			},
58
		},
59
		{
60
			"validate command with long url",
61
			[]string{
62
				"validate",
63
				"--specification-url",
64
				testSpecificationURL,
65
			},
66
		},
67
		{
68
			"help command with short argument",
69
			[]string{"-h"},
70
		},
71
		{
72
			"help command with long argument",
73
			[]string{"--help"},
74
		},
75
	}
76
	for _, test := range tests {
77
		t.Run(test.name, func(t *testing.T) {
78
			args := append(test.arguments, "--dry-run")
79
80
			err := Execute(Arguments(args))
81
82
			assert.NoError(t, err)
83
		})
84
	}
85
}
86
87
func TestExecute_InvalidArguments_Error(t *testing.T) {
88
	tests := []struct {
89
		name      string
90
		arguments []string
91
		error     string
92
	}{
93
		{
94
			"no specification url",
95
			[]string{"serve"},
96
			"failed to load OpenAPI specification from '': open : no such file or directory",
97
		},
98
	}
99
	for _, test := range tests {
100
		t.Run(test.name, func(t *testing.T) {
101
			args := append(test.arguments, "--dry-run")
102
103
			err := Execute(Arguments(args))
104
105
			assert.EqualError(t, err, test.error)
106
		})
107
	}
108
}
109