Skip to content

Commit 30a9067

Browse files
Mo3m3noktalz
authored andcommitted
BUILD/MINOR: Enable linters in deploy/test dir
Remove uncessary setup in .golangci.yml and enable linters in deploy/test dir
1 parent 008a5b7 commit 30a9067

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

.golangci.yml

-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
linters-settings:
22
govet:
33
check-shadowing: true
4-
golint:
5-
min-confidence: 0
64
gocyclo:
75
min-complexity: 25
86
maligned:
97
suggest-new: true
108
dupl:
119
threshold: 200
12-
goconst:
13-
min-len: 2
14-
min-occurrences: 2
1510

1611
linters:
1712
enable-all: true
@@ -35,7 +30,3 @@ linters:
3530
- wrapcheck
3631
- wsl
3732
- nakedret
38-
39-
run:
40-
skip-dirs:
41-
- test

controller/annotations/ingress/1

Whitespace-only changes.

deploy/tests/e2e/client.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ type GlobalHAProxyInfo struct {
4141
Uptime string
4242
}
4343

44-
const HTTP_PORT = 30080
45-
const HTTPS_PORT = 30443
46-
const STATS_PORT = 31024
44+
//nolint:golint, stylecheck
45+
const (
46+
HTTP_PORT = 30080
47+
HTTPS_PORT = 30443
48+
STATS_PORT = 31024
49+
)
4750

4851
func newClient(host string, port int, tls bool) (*Client, error) {
4952
kindURL := os.Getenv("KIND_URL")
@@ -70,8 +73,7 @@ func newClient(host string, port int, tls bool) (*Client, error) {
7073
Transport: &http.Transport{
7174
DialContext: func(ctx context.Context, network, addr string) (conn net.Conn, e error) {
7275
dialer := &net.Dialer{}
73-
addr = fmt.Sprintf("%s:%d", kindURL, dstPort)
74-
return dialer.DialContext(ctx, network, addr)
76+
return dialer.DialContext(ctx, network, fmt.Sprintf("%s:%d", kindURL, dstPort))
7577
},
7678
},
7779
}, nil
@@ -99,6 +101,7 @@ func NewHTTPSClient(host string, port ...int) (*Client, error) {
99101
return nil, err
100102
}
101103
client.Transport.TLSClientConfig = &tls.Config{
104+
//nolint:gosec // skipping TLS verify for testing purpose
102105
InsecureSkipVerify: true,
103106
}
104107
return client, nil

deploy/tests/e2e/utils.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
var WaitDuration = 60 * time.Second
2121
var TickDuration = 2 * time.Second
2222

23-
var devModeFlag = flag.Bool("dev", false, "keep test environmnet after finishing")
23+
var devModeFlag = flag.Bool("dev", false, "keep test environment after finishing")
2424
var devMode bool
2525

2626
type Test struct {
@@ -37,10 +37,13 @@ func NewTest() (test Test, err error) {
3737
test = Test{}
3838
// Namespace
3939
if test.namespace, err = setupNamespace(); err != nil {
40-
return test, fmt.Errorf("error setting test namespace %s:", err)
40+
return test, fmt.Errorf("error setting test namespace: %w", err)
4141
}
4242
deleteNamespace(test.namespace, true)
43-
test.execute("", "kubectl", "create", "ns", test.namespace)
43+
_, err = test.execute("", "kubectl", "create", "ns", test.namespace)
44+
if err != nil {
45+
return test, fmt.Errorf("error creating test namespace : %w ", err)
46+
}
4447
// TearDownFuncs
4548
test.tearDownFuncs = []TearDownFunc{func() error {
4649
deleteNamespace(test.namespace, false)
@@ -49,7 +52,7 @@ func NewTest() (test Test, err error) {
4952
// TemplateDir
5053
test.templateDir, err = ioutil.TempDir("/tmp/", "haproxy-ic-test-tmpl")
5154
if err != nil {
52-
return test, fmt.Errorf("error creating template dir: %s ", err.Error())
55+
return test, fmt.Errorf("error creating template dir: %w ", err)
5356
}
5457
return test, nil
5558
}
@@ -61,7 +64,7 @@ func (t *Test) GetNS() string {
6164
func (t *Test) DeployYaml(path string, namespace string) error {
6265
yaml, err := ioutil.ReadFile(path)
6366
if err != nil {
64-
return fmt.Errorf("error reading yaml file: %s", err)
67+
return fmt.Errorf("error reading yaml file: %w", err)
6568
}
6669
// kubectl -n $NS apply -f -
6770
out, err := t.execute(string(yaml), "kubectl", "-n", namespace, "apply", "-f", "-")
@@ -74,18 +77,18 @@ func (t *Test) DeployYaml(path string, namespace string) error {
7477
func (t *Test) DeployYamlTemplate(path string, namespace string, data interface{}) error {
7578
file, err := ioutil.ReadFile(path)
7679
if err != nil {
77-
return fmt.Errorf("error reading yaml template: %s", err)
80+
return fmt.Errorf("error reading yaml template: %w", err)
7881
}
7982
var result bytes.Buffer
8083
tmpl := template.Must(template.New("").Parse(string(file)))
8184
err = tmpl.Execute(&result, data)
8285
if err != nil {
83-
return fmt.Errorf("error parsing yaml template: %s", err)
86+
return fmt.Errorf("error parsing yaml template: %w", err)
8487
}
8588
yaml := filepath.Join(t.templateDir, t.namespace+time.Now().Format("2006-01-02-1504051111")+".yaml")
86-
err = ioutil.WriteFile(yaml, result.Bytes(), 0644)
89+
err = ioutil.WriteFile(yaml, result.Bytes(), 0600)
8790
if err != nil {
88-
return fmt.Errorf("error writing generated yaml template: %s", err)
91+
return fmt.Errorf("error writing generated yaml template: %w", err)
8992
}
9093
return t.DeployYaml(yaml, namespace)
9194
}
@@ -124,7 +127,6 @@ func (t *Test) GetK8sVersion() (major, minor int, err error) {
124127
major, _ = strconv.Atoi(version.Major)
125128
minor, _ = strconv.Atoi(version.Minor)
126129
return major, minor, nil
127-
128130
}
129131

130132
func (t *Test) execute(entry, command string, args ...string) (string, error) {
@@ -141,7 +143,7 @@ func deleteNamespace(namespace string, newSetup bool) {
141143
return
142144
}
143145
deleteCmd := exec.Command("kubectl", "delete", "namespace", namespace)
144-
deleteCmd.Run()
146+
_ = deleteCmd.Run()
145147
}
146148

147149
func setupNamespace() (string, error) {

0 commit comments

Comments
 (0)