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

Fix new version linter issues #101

Merged
merged 6 commits into from
Mar 18, 2020
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
Expand Up @@ -42,6 +42,10 @@ linters:
- gosec
- gochecknoinits
- gochecknoglobals
- funlen
- gocognit
- godox
- wsl

issues:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ errcheck:

lint: fmtcheck
@echo "==> Checking source code against linters..."
@GOGC=30 golangci-lint run
@GOGC=30 golangci-lint run --timeout=30m

tools:
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
Expand Down
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type Credentials struct {

// NewClient returns a new Nutanix API client.
func NewClient(credentials *Credentials) (*Client, error) {

transCfg := &http.Transport{
// nolint:gas
TLSClientConfig: &tls.Config{InsecureSkipVerify: credentials.Insecure}, // ignore expired SSL certificates
Expand Down Expand Up @@ -156,9 +155,11 @@ func (c *Client) OnRequestCompleted(rc RequestCompletionCallback) {
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) error {
req = req.WithContext(ctx)
resp, err := c.client.Do(req)

if err != nil {
return err
}

defer func() {
if rerr := resp.Body.Close(); err == nil {
err = rerr
Expand Down
11 changes: 11 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestCheckResponse(t *testing.T) {
func TestDo(t *testing.T) {
ctx := context.TODO()
mux, client, server := setup()

defer server.Close()

type foo struct {
Expand Down Expand Up @@ -150,6 +151,7 @@ func TestDo(t *testing.T) {
func TestDo_httpError(t *testing.T) {
ctx := context.TODO()
mux, client, server := setup()

defer server.Close()

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -247,6 +249,7 @@ func TestClient_NewRequest(t *testing.T) {
urlStr string
body interface{}
}

tests := []struct {
name string
fields fields
Expand All @@ -256,6 +259,7 @@ func TestClient_NewRequest(t *testing.T) {
}{
// TODO: Add test cases.
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -292,6 +296,7 @@ func TestClient_NewUploadRequest(t *testing.T) {
urlStr string
body []byte
}

tests := []struct {
name string
fields fields
Expand All @@ -301,6 +306,7 @@ func TestClient_NewUploadRequest(t *testing.T) {
}{
// TODO: Add test cases.
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -341,6 +347,7 @@ func TestClient_OnRequestCompleted(t *testing.T) {
}{
// TODO: Add test cases.
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -369,6 +376,7 @@ func TestClient_Do(t *testing.T) {
req *http.Request
v interface{}
}

tests := []struct {
name string
fields fields
Expand All @@ -377,6 +385,7 @@ func TestClient_Do(t *testing.T) {
}{
// TODO: Add test cases.
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -399,13 +408,15 @@ func Test_fillStruct(t *testing.T) {
data map[string]interface{}
result interface{}
}

tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 13 additions & 2 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (op Operations) DeleteVM(uuid string) (*DeleteResponse, error) {

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -196,6 +197,7 @@ func (op Operations) DeleteSubnet(uuid string) (*DeleteResponse, error) {

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -312,13 +314,14 @@ func (op Operations) UploadImage(uuid, filepath string) error {
}

req, err := op.client.NewUploadRequest(ctx, http.MethodPut, path, fileContents)

if err != nil {
return fmt.Errorf("error: Creating request %s", err)
}

err = op.client.Do(ctx, req, nil)

return err

}

/*DeleteImage deletes a IMAGE
Expand All @@ -334,6 +337,7 @@ func (op Operations) DeleteImage(uuid string) (*DeleteResponse, error) {

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}
Expand All @@ -358,6 +362,7 @@ func (op Operations) GetImage(uuid string) (*ImageIntentResponse, error) {
if err != nil {
return nil, err
}

return imageIntentResponse, op.client.Do(ctx, req, imageIntentResponse)
}

Expand Down Expand Up @@ -669,6 +674,7 @@ func (op Operations) DeleteNetworkSecurityRule(uuid string) (*DeleteResponse, er

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -836,7 +842,7 @@ func (op Operations) UpdateVolumeGroup(uuid string, body *VolumeGroupInput) (*Vo
return networkSecurityRuleResponse, op.client.Do(ctx, req, networkSecurityRuleResponse)
}

const itemsPerPage = int64(100)
const itemsPerPage int64 = 100

func hasNext(ri *int64) bool {
*ri -= itemsPerPage
Expand Down Expand Up @@ -876,6 +882,7 @@ func (op Operations) ListAllVM() (*VMListIntentResponse, error) {

offset += itemsPerPage
}

resp.Entities = entities
}

Expand Down Expand Up @@ -916,6 +923,7 @@ func (op Operations) ListAllSubnet() (*SubnetListIntentResponse, error) {
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

Expand Down Expand Up @@ -956,6 +964,7 @@ func (op Operations) ListAllNetworkSecurityRule() (*NetworkSecurityRuleListInten
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

Expand Down Expand Up @@ -996,6 +1005,7 @@ func (op Operations) ListAllImage() (*ImageListIntentResponse, error) {
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

Expand Down Expand Up @@ -1036,6 +1046,7 @@ func (op Operations) ListAllCluster() (*ClusterListIntentResponse, error) {
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

Expand Down
Loading