GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#3)
by Victor Hugo
01:17
created

devto.TestNewConfig   B

Complexity

Conditions 7

Size

Total Lines 60
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 45
dl 0
loc 60
rs 7.4
c 0
b 0
f 0
nop 1

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 devto
2
3
import (
4
	"reflect"
5
	"testing"
6
)
7
8
func TestNewConfig(t *testing.T) {
9
	type args struct {
10
		p bool
11
		k string
12
	}
13
	tests := []struct {
14
		name    string
15
		a       args
16
		want    Config
17
		wantErr bool
18
		err     error
19
	}{
20
		{
21
			name: "new config call is successful for public endpoints",
22
			a: args{
23
				p: false,
24
				k: "",
25
			},
26
			want: Config{
27
				InsecureOnly: true,
28
				APIKey:       "",
29
			},
30
			wantErr: false,
31
			err:     nil,
32
		},
33
		{
34
			name: "new config call is successful for protected endpoints",
35
			a: args{
36
				p: true,
37
				k: "dummy-api-key",
38
			},
39
			want: Config{
40
				InsecureOnly: false,
41
				APIKey:       "dummy-api-key",
42
			},
43
			wantErr: false,
44
			err:     nil,
45
		},
46
		{
47
			name: "new config call fails for protected access without a key",
48
			a: args{
49
				p: true,
50
				k: "",
51
			},
52
			want:    Config{},
53
			wantErr: true,
54
			err:     ErrMissingRequiredParameter,
55
		},
56
	}
57
58
	for _, tt := range tests {
59
		t.Run(tt.name, func(t *testing.T) {
60
			got, err := NewConfig(tt.a.p, tt.a.k)
61
			if tt.wantErr && err != nil {
62
				if !reflect.DeepEqual(err, tt.err) {
63
					t.Errorf("failed on error expectation, got: %v | want %v", err, tt.err)
64
				}
65
			} else {
66
				if !reflect.DeepEqual(tt.want, *got) {
67
					t.Errorf("missmatched expectation, got: %v, want: %v", got, tt.want)
68
				}
69
			}
70
		})
71
	}
72
}
73