Skip to content

Commit

Permalink
style: Fix lost variable assignments and enable ineffassign linter (#…
Browse files Browse the repository at this point in the history
…3732)

See #3565

Signed-off-by: Bryon Nevis <[email protected]>

Co-authored-by: Cloud Tsai <[email protected]>
  • Loading branch information
bnevis-i and cloudxxx8 authored Sep 29, 2021
1 parent cbc80a6 commit f3063e0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ linters:
disable:
- errcheck
- gosimple
- ineffassign
- staticcheck
- varcheck
2 changes: 2 additions & 0 deletions internal/core/data/controller/http/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func TestDeleteEventsByDeviceName(t *testing.T) {
ec := NewEventController(dic)

req, err := http.NewRequest(http.MethodDelete, common.ApiEventByDeviceNameRoute, http.NoBody)
assert.NoError(t, err)
req = mux.SetURLVars(req, map[string]string{common.Name: deviceName})
require.NoError(t, err)

Expand All @@ -470,6 +471,7 @@ func TestDeleteEventsByDeviceName(t *testing.T) {

var actualResponse commonDTO.BaseResponse
err = json.Unmarshal(recorder.Body.Bytes(), &actualResponse)
assert.NoError(t, err)

assert.Equal(t, common.ApiVersion, actualResponse.ApiVersion, "API Version not as expected")
assert.Equal(t, http.StatusAccepted, recorder.Result().StatusCode, "HTTP status code not as expected")
Expand Down
5 changes: 4 additions & 1 deletion internal/core/metadata/controller/http/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"mime/multipart"
"net/http"
"net/http/httptest"
"strings"
"testing"

"gopkg.in/yaml.v3"

"github.com/edgexfoundry/edgex-go/internal/core/metadata/config"
"github.com/edgexfoundry/edgex-go/internal/core/metadata/container"
dbMock "github.com/edgexfoundry/edgex-go/internal/core/metadata/infrastructure/interfaces/mocks"
Expand Down Expand Up @@ -532,6 +533,7 @@ func TestAddDeviceProfileByYaml_BadRequest(t *testing.T) {
handler.ServeHTTP(recorder, req)
var res commonDTO.BaseWithIdResponse
err = json.Unmarshal(recorder.Body.Bytes(), &res)
assert.NoError(t, err)

// Assert
assert.Equal(t, http.StatusBadRequest, recorder.Result().StatusCode, "HTTP status code not as expected")
Expand Down Expand Up @@ -693,6 +695,7 @@ func TestUpdateDeviceProfileByYaml(t *testing.T) {
handler.ServeHTTP(recorder, req)
var res commonDTO.BaseWithIdResponse
err = json.Unmarshal(recorder.Body.Bytes(), &res)
assert.NoError(t, err)

// Assert
assert.Equal(t, testCase.expectedStatusCode, recorder.Result().StatusCode, "HTTP status code not as expected")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func TestAddDeviceService(t *testing.T) {
} else {
var res commonDTO.BaseResponse
err = json.Unmarshal(recorder.Body.Bytes(), &res)
assert.NoError(t, err)
assert.Equal(t, testCase.expectedHttpStatusCode, recorder.Result().StatusCode, "HTTP status code not as expected")
assert.Equal(t, testCase.expectedHttpStatusCode, res.StatusCode, "BaseResponse status code not as expected")
assert.NotEmpty(t, res.Message, "Response message doesn't contain the error message")
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/infrastructure/redis/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func getObjectsBySomeRange(conn redis.Conn, command string, key string, offset i
if limit == -1 { //-1 limit means that clients want to retrieve all remaining records after offset from DB, so specifying -1 for end
end = limit
}
count, err := redis.Int(conn.Do(ZCOUNT, key, InfiniteMin, InfiniteMax))
count, _ := redis.Int(conn.Do(ZCOUNT, key, InfiniteMin, InfiniteMax))
if count == 0 { // return nil slice when there is no records in the DB
return nil, nil
} else if count > 0 && start > count { // return RangeNotSatisfiable error when start is out of range
Expand All @@ -91,7 +91,7 @@ func getObjectsByScoreRange(conn redis.Conn, key string, start int, end int, off
if limit == 0 {
return
}
count, err := redis.Int(conn.Do(ZCOUNT, key, start, end))
count, _ := redis.Int(conn.Do(ZCOUNT, key, start, end))
if count == 0 { // return nil slice when there is no records satisfied with the score range in the DB
return nil, nil
} else if count > 0 && offset >= count { // return RangeNotSatisfiable error when offset is out of range
Expand Down
4 changes: 1 addition & 3 deletions internal/security/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,10 @@ func (s *Service) postCert(cp bootstrapConfig.CertKeyPair) *CertError {
why := string(b)
message := fmt.Sprintf("failed to add certificate with errorcode %d, error %s", resp.StatusCode, why)
s.loggingClient.Error(message)
e := &CertError{message, InternalError}
if (resp.StatusCode == http.StatusBadRequest) && (strings.Index(why, "existing certificate") != -1) {
message = fmt.Sprintf("certificate already exists on reverse proxy")
}
e = &CertError{message, CertExisting}
return e
return &CertError{message, CertExisting}
}
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/security/secretstore/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func (cs *Certs) ReadFrom(certPath string, keyPath string) (*CertPair, error) {
func (cs *Certs) UploadToStore(cp *CertPair) error {
cs.loggingClient.Info("trying to upload the proxy cert pair into secret store")
jsonBytes, err := json.Marshal(cp)
if err != nil {
return err
}
body := bytes.NewBuffer(jsonBytes)

certUrl, err := cs.certPathUrl()
Expand Down
3 changes: 3 additions & 0 deletions internal/security/secretstore/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (cr *Cred) GeneratePassword(ctx context.Context) (string, error) {
func (cr *Cred) UploadToStore(pair *UserPasswordPair, path string) error {
cr.loggingClient.Debug("trying to upload the credential pair into secret store")
jsonBytes, err := json.Marshal(pair)
if err != nil {
return err
}
body := bytes.NewBuffer(jsonBytes)

credURL, err := cr.credPathURL(path)
Expand Down

0 comments on commit f3063e0

Please sign in to comment.