Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added "make lint" target and added to "make test" target #302

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters:
disable:
enable:
- gosec
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
.PHONY: test
.PHONY: test unittest lint

GO=CGO_ENABLED=0 GO111MODULE=on go
ARCH=$(shell uname -m)

tidy:
go mod tidy

test:
unittest:
$(GO) test ./... -coverprofile=coverage.out ./...

lint:
@which golangci-lint >/dev/null || echo "WARNING: go linter not installed. To install, run\n curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b \$$(go env GOPATH)/bin v1.42.1"
@if [ "z${ARCH}" = "zx86_64" ] && which golangci-lint >/dev/null ; then golangci-lint run --config .golangci.yml ; else echo "WARNING: Linting skipped (not on x86_64 or linter not installed)"; fi


test: unittest lint
$(GO) vet ./...
gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")
[ "`gofmt -l $$(find . -type f -name '*.go'| grep -v "/vendor/")`" = "" ]
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func translateInterruptToCancel(ctx context.Context, wg *sync.WaitGroup, cancel
go func() {
defer wg.Done()

signalStream := make(chan os.Signal)
signalStream := make(chan os.Signal, 1)
defer func() {
signal.Stop(signalStream)
close(signalStream)
Expand Down Expand Up @@ -155,7 +155,7 @@ func RunAndReturnWaitGroup(
// call individual bootstrap handlers.
startedSuccessfully := true
for i := range handlers {
if handlers[i](ctx, &wg, startupTimer, dic) == false {
if !handlers[i](ctx, &wg, startupTimer, dic) {
cancel()
startedSuccessfully = false
break
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestValidateSecrets(t *testing.T) {
result := ValidateSecretData(test.AuthMode, "unit-test", &test.SecretData)
if test.ErrorExpectation {
require.Error(t, result, "Result should be an error")
assert.Equal(t, test.ErrorMessage, result.(error).Error())
assert.Equal(t, test.ErrorMessage, result.Error())
} else {
assert.Nil(t, result, "Should be nil")
}
Expand Down
1 change: 1 addition & 0 deletions bootstrap/secret/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
expectedPath = "/redisdb"
)

//nolint: gosec
var testTokenResponse = `{"auth":{"accessor":"9OvxnrjgV0JTYMeBreak7YJ9","client_token":"s.oPJ8uuJCkTRb2RDdcNova8wg","entity_id":"","lease_duration":3600,"metadata":{"edgex-service-name":"edgex-core-data"},"orphan":true,"policies":["default","edgex-service-edgex-core-data"],"renewable":true,"token_policies":["default","edgex-service-edgex-core-data"],"token_type":"service"},"data":null,"lease_duration":0,"lease_id":"","renewable":false,"request_id":"ee749ee1-c8bf-6fa9-3ed5-644181fc25b0","warnings":null,"wrap_info":null}`
var expectedSecrets = map[string]string{UsernameKey: expectedUsername, PasswordKey: expectedPassword}

Expand Down
3 changes: 2 additions & 1 deletion bootstrap/secret/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import (
const (
TokenTypeConsul = "consul"
AccessTokenAuthError = "HTTP response with status code 403"
SecretsAuthError = "Received a '403' response"
//nolint: gosec
SecretsAuthError = "Received a '403' response"
)

// SecureProvider implements the SecretProvider interface
Expand Down
1 change: 1 addition & 0 deletions bootstrap/secret/secure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func TestSecureProvider_SecretsUpdated(t *testing.T) {

func TestSecureProvider_DefaultTokenExpiredCallback(t *testing.T) {
goodTokenFile := "good-token.json"
//nolint: gosec
badTokenFile := "bad-token.json"
sameTokenFile := "same-token.json"
newToken := "new token"
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/secret/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func TestServiceSecrets_UnmarshalJson_Imported_true(t *testing.T) {
func TestServiceSecrets_UnmarshalJson_Failed_Validation(t *testing.T) {
allGood := `{"secrets": [{"path": "auth","imported": false,"secretData": [{"key": "user1","value": "password1"}]}]}`
noPath := `{"secrets": [{"path": "","imported": false,"secretData": [{"key": "user1","value": "password1"}]}]}`
//nolint: gosec
noSecretData := `{"secrets": [{"path": "auth","imported": false}]}`
//nolint: gosec
emptySecretData := `{"secrets": [{"path": "auth","imported": false, "secretData": []}]}`
missingKey := `{"secrets": [{"path": "auth","imported": false,"secretData": [{"value": "password1"}]}]}`
missingValue := `{"secrets": [{"path": "auth","imported": false,"secretData": [{"key": "user1"}]}]}`
Expand Down