Skip to content

Commit

Permalink
Add gofumpt linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Jun 23, 2021
1 parent 181e18a commit 085ac90
Show file tree
Hide file tree
Showing 27 changed files with 134 additions and 118 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- errcheck
- errorlint
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
Expand Down
5 changes: 2 additions & 3 deletions cmd/nginx-ingress/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ func TestValidatePort(t *testing.T) {
t.Errorf("Error for valid port: %v err: %v\n", goodPort, err)
}
}

}

func TestParseNginxStatusAllowCIDRs(t *testing.T) {
var badCIDRs = []struct {
badCIDRs := []struct {
input string
expectedError error
}{
Expand All @@ -53,7 +52,7 @@ func TestParseNginxStatusAllowCIDRs(t *testing.T) {
}
}

var goodCIDRs = []struct {
goodCIDRs := []struct {
input string
expected []string
}{
Expand Down
4 changes: 2 additions & 2 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const (
spiffeCertFileName = "spiffe_cert.pem"
spiffeKeyFileName = "spiffe_key.pem"
spiffeBundleFileName = "spiffe_rootca.pem"
spiffeCertsFileMode = os.FileMode(0644)
spiffeKeyFileMode = os.FileMode(0600)
spiffeCertsFileMode = os.FileMode(0o644)
spiffeKeyFileMode = os.FileMode(0o600)
)

// ExtendedResources holds all extended configuration resources, for which Configurator configures NGINX.
Expand Down
5 changes: 3 additions & 2 deletions internal/configs/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ func createMergeableCafeIngress() *MergeableIngresses {
"/tea": true,
},
SecretRefs: map[string]*secrets.SecretReference{},
}},
},
},
}

return mergeableIngresses
Expand Down Expand Up @@ -880,7 +881,7 @@ func TestIsSSLEnabled(t *testing.T) {
NginxServiceMesh,
Expected bool
}
var testCases = []testCase{
testCases := []testCase{
{
IsSSLService: false,
SpiffeServerCerts: false,
Expand Down
42 changes: 21 additions & 21 deletions internal/configs/parsing_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var configMap = v1.ConfigMap{
APIVersion: "v1",
},
}

var ingress = v1beta1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "test",
Expand Down Expand Up @@ -230,7 +231,6 @@ func TestGetMapKeyAsStringSlice(t *testing.T) {
if !reflect.DeepEqual(expected, slice) {
t.Errorf("Unexpected return value:\nGot: %#v\nExpected: %#v", slice, expected)
}

}

func TestGetMapKeyAsStringSliceMultilineSnippets(t *testing.T) {
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestGetMapKeyAsStringSliceNotFound(t *testing.T) {
}

func TestParseLBMethod(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected string
}{
Expand All @@ -281,7 +281,7 @@ func TestParseLBMethod(t *testing.T) {
{"hash $request_id consistent", "hash $request_id consistent"},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blabla",
"least_time header",
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestParseLBMethod(t *testing.T) {
}

func TestParseLBMethodForPlus(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected string
}{
Expand All @@ -332,7 +332,7 @@ func TestParseLBMethodForPlus(t *testing.T) {
{"least_time last_byte inflight", "least_time last_byte inflight"},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blabla",
"hash123",
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestParseLBMethodForPlus(t *testing.T) {
}

func TestParseTime(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected string
}{
Expand All @@ -381,7 +381,7 @@ func TestParseTime(t *testing.T) {
{"100y", "100y"},
{"600", "600s"},
}
var invalidInput = []string{"5s 5s", "ss", "rM", "m0m", "s1s", "-5s", "", "1L", "11 11", " ", " "}
invalidInput := []string{"5s 5s", "ss", "rM", "m0m", "s1s", "-5s", "", "1L", "11 11", " ", " "}

for _, test := range testsWithValidInput {
result, err := ParseTime(test.input)
Expand All @@ -403,8 +403,8 @@ func TestParseTime(t *testing.T) {
}

func TestParseOffset(t *testing.T) {
var testsWithValidInput = []string{"1", "2k", "2K", "3m", "3M", "4g", "4G"}
var invalidInput = []string{"-1", "", "blah"}
testsWithValidInput := []string{"1", "2k", "2K", "3m", "3M", "4g", "4G"}
invalidInput := []string{"-1", "", "blah"}
for _, test := range testsWithValidInput {
result, err := ParseOffset(test)
if err != nil {
Expand All @@ -423,8 +423,8 @@ func TestParseOffset(t *testing.T) {
}

func TestParseSize(t *testing.T) {
var testsWithValidInput = []string{"1", "2k", "2K", "3m", "3M"}
var invalidInput = []string{"-1", "", "blah", "4g", "4G"}
testsWithValidInput := []string{"1", "2k", "2K", "3m", "3M"}
invalidInput := []string{"-1", "", "blah", "4g", "4G"}
for _, test := range testsWithValidInput {
result, err := ParseSize(test)
if err != nil {
Expand All @@ -443,8 +443,8 @@ func TestParseSize(t *testing.T) {
}

func TestParseProxyBuffersSpec(t *testing.T) {
var testsWithValidInput = []string{"1 1k", "10 24k", "2 2K", "6 3m", "128 3M"}
var invalidInput = []string{"-1", "-6 2k", "", "blah", "16k", "10M", "2 4g", "3 4G"}
testsWithValidInput := []string{"1 1k", "10 24k", "2 2K", "6 3m", "128 3M"}
invalidInput := []string{"-1", "-6 2k", "", "blah", "16k", "10M", "2 4g", "3 4G"}
for _, test := range testsWithValidInput {
result, err := ParseProxyBuffersSpec(test)
if err != nil {
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestVerifyThresholds(t *testing.T) {
}

func TestParseBool(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected bool
}{
Expand All @@ -507,7 +507,7 @@ func TestParseBool(t *testing.T) {
{"false", false},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blablah",
"-100",
Expand All @@ -534,7 +534,7 @@ func TestParseBool(t *testing.T) {
}

func TestParseInt(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected int
}{
Expand All @@ -544,7 +544,7 @@ func TestParseInt(t *testing.T) {
{"123456789", 123456789},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blablah",
"10000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -571,7 +571,7 @@ func TestParseInt(t *testing.T) {
}

func TestParseInt64(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected int64
}{
Expand All @@ -581,7 +581,7 @@ func TestParseInt64(t *testing.T) {
{"123456789", 123456789},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blablah",
"10000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -608,7 +608,7 @@ func TestParseInt64(t *testing.T) {
}

func TestParseUint64(t *testing.T) {
var testsWithValidInput = []struct {
testsWithValidInput := []struct {
input string
expected uint64
}{
Expand All @@ -618,7 +618,7 @@ func TestParseUint64(t *testing.T) {
{"123456789", 123456789},
}

var invalidInput = []string{
invalidInput := []string{
"",
"blablah",
"10000000000000000000000000000000000000000000000000000000000000000",
Expand Down
2 changes: 0 additions & 2 deletions internal/configs/transportserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func TestGenerateTransportServerConfigForTCP(t *testing.T) {
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("generateTransportServerConfig() mismatch (-want +got):\n%s", diff)
}

}

func TestGenerateTransportServerConfigForTCPMaxConnections(t *testing.T) {
Expand Down Expand Up @@ -313,7 +312,6 @@ func TestGenerateTransportServerConfigForTCPMaxConnections(t *testing.T) {
if diff := cmp.Diff(expected, result); diff != "" {
t.Errorf("generateTransportServerConfig() mismatch (-want +got):\n%s", diff)
}

}

func TestGenerateTransportServerConfigForTLSPasstrhough(t *testing.T) {
Expand Down
28 changes: 16 additions & 12 deletions internal/configs/version1/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"text/template"
)

const nginxIngressTmpl = "nginx.ingress.tmpl"
const nginxMainTmpl = "nginx.tmpl"
const nginxPlusIngressTmpl = "nginx-plus.ingress.tmpl"
const nginxPlusMainTmpl = "nginx-plus.tmpl"
const (
nginxIngressTmpl = "nginx.ingress.tmpl"
nginxMainTmpl = "nginx.tmpl"
nginxPlusIngressTmpl = "nginx-plus.ingress.tmpl"
nginxPlusMainTmpl = "nginx-plus.tmpl"
)

var testUps = Upstream{
Name: "test",
Expand All @@ -26,14 +28,16 @@ var testUps = Upstream{
},
}

var headers = map[string]string{"Test-Header": "test-header-value"}
var healthCheck = HealthCheck{
UpstreamName: "test",
Fails: 1,
Interval: 1,
Passes: 1,
Headers: headers,
}
var (
headers = map[string]string{"Test-Header": "test-header-value"}
healthCheck = HealthCheck{
UpstreamName: "test",
Fails: 1,
Interval: 1,
Passes: 1,
Headers: headers,
}
)

var ingCfg = IngressNginxConfig{

Expand Down
10 changes: 6 additions & 4 deletions internal/configs/version2/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"testing"
)

const nginxPlusVirtualServerTmpl = "nginx-plus.virtualserver.tmpl"
const nginxVirtualServerTmpl = "nginx.virtualserver.tmpl"
const nginxPlusTransportServerTmpl = "nginx-plus.transportserver.tmpl"
const nginxTransportServerTmpl = "nginx.transportserver.tmpl"
const (
nginxPlusVirtualServerTmpl = "nginx-plus.virtualserver.tmpl"
nginxVirtualServerTmpl = "nginx.virtualserver.tmpl"
nginxPlusTransportServerTmpl = "nginx-plus.transportserver.tmpl"
nginxTransportServerTmpl = "nginx.transportserver.tmpl"
)

var virtualServerCfg = VirtualServerConfig{
LimitReqZones: []LimitReqZone{
Expand Down
9 changes: 6 additions & 3 deletions internal/k8s/appprotect/app_protect_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,18 @@ func createAppProtectUserSigEx(userSigObj *unstructured.Unstructured) (*UserSigE
errMsg := invalidTimestampErrorMsg
return &UserSigEx{Obj: userSigObj, IsValid: false, ErrorMsg: errMsg}, fmt.Errorf(errMsg)
}
return &UserSigEx{Obj: userSigObj,
return &UserSigEx{
Obj: userSigObj,
Tag: sTag,
RevTime: &revTime,
IsValid: true}, nil
IsValid: true,
}, nil
}
return &UserSigEx{
Obj: userSigObj,
Tag: sTag,
IsValid: true}, nil
IsValid: true,
}, nil
}

func isReqSatisfiedByUserSig(sigReq SignatureReq, sig *UserSigEx) bool {
Expand Down

0 comments on commit 085ac90

Please sign in to comment.