Skip to content

Commit

Permalink
Implemented first batch of suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
palczyn committed Sep 9, 2021
1 parent 9b226c5 commit c936e46
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 269 deletions.
26 changes: 10 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ issues:
- should not use underscores in package names
# EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments
- (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
- (struct (of|with)|could be)
exclude-use-default: false
exclude-rules: # exclude linters impossible to exclude via //nolint
- path: ^kentikapi/models/enum_ # these files are generated and shouldn't be edited with //nolint
Expand All @@ -28,20 +27,20 @@ issues:
# Disabled linters:
# - cyclop - duplicates functionality of gocyclo
# - exhaustivestruct - breaks "Make the zero value useful" proverb, meant to be used only for special cases
# - funlen - only test functions exceeds the line limit of 60 - too strict, these functions are easily readable
# - funlen - not needed - gocyclo ensures that functions complexity is not too high
# - godox - requires all TODOs to be removed - too strict
# - golint - deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner
# - gomoddirectives - does not allow "replace" directives - too strict
# - goerr113 - following check is too strict: "do not define dynamic errors, use wrapped static errors instead",
# the check cannot be disabled
# - interfacer - deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner
# - maligned - deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner
# - nlreturn - leads to using too many line breaks
# - prealloc - from docs:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
# - paralleltest - premature optimization
# - prealloc - considered a premature optimization.
# - scopelint - deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner
# - thelper - enforcing t.Helper() everywhere is too strict
# - wrapcheck - valuable linter which I think needs higher level knowledge on the project to be fixed
# - wrapcheck - valuable linter, TODO: ignore false-positives (interfaces, internal imports) and adjust the code to comply
# - wsl - leads to using too many line breaks
linters:
enable:
Expand Down Expand Up @@ -70,7 +69,6 @@ linters:
- gofumpt
- goheader
- goimports
- revive
- gomnd
- gomodguard
- goprintffuncname
Expand All @@ -88,7 +86,6 @@ linters:
- nilerr
- noctx
- nolintlint
- paralleltest
- predeclared
- revive
- rowserrcheck
Expand All @@ -107,24 +104,21 @@ linters:
- whitespace

linters-settings:
dupl:
tests: false
errcheck:
check-type-assertions: true
check-blank: true
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors - too strict
errorf: false
gocyclo:
min-complexity: 11
golint:
min-confidence: 0
gosec:
tests: false
min-complexity: 10
govet:
disable:
# Reordering struct fields may decrease readability
- fieldalignment
enable-all: true
lll:
# lines longer than 127 will be reported, 120 is default
# TODO: 120 (default) should be achieved to increase comfort of window split view
line-length: 127
nakedret:
max-func-lines: 5
10 changes: 5 additions & 5 deletions apiv6/examples/cloud_export/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func runCRUD(client *kentikapi.Client) error {
createReqPayload := *cloudexport.NewV202101beta1CreateCloudExportRequest()
createReqPayload.Export = export

createResp, httpResp, err := client.CloudExportAdminServiceApi.
createResp, httpResp, err := client.CloudExportAdminServiceAPI.
ExportCreate(context.Background()).
Body(createReqPayload).
Execute()
Expand All @@ -57,7 +57,7 @@ func runCRUD(client *kentikapi.Client) error {
updateReqPayload := *cloudexport.NewV202101beta1UpdateCloudExportRequest()
updateReqPayload.Export = created

updateResp, httpResp, err := client.CloudExportAdminServiceApi.
updateResp, httpResp, err := client.CloudExportAdminServiceAPI.
ExportUpdate(context.Background(), *created.Id).
Body(updateReqPayload).
Execute()
Expand All @@ -68,7 +68,7 @@ func runCRUD(client *kentikapi.Client) error {
fmt.Println()

fmt.Println("### GET")
getResp, httpResp, err := client.CloudExportAdminServiceApi.
getResp, httpResp, err := client.CloudExportAdminServiceAPI.
ExportGet(context.Background(), *created.Id).
Execute()
if err != nil {
Expand All @@ -78,7 +78,7 @@ func runCRUD(client *kentikapi.Client) error {
fmt.Println()

fmt.Println("### DELETE")
deleteResp, httpResp, err := client.CloudExportAdminServiceApi.
deleteResp, httpResp, err := client.CloudExportAdminServiceAPI.
ExportDelete(context.Background(), *created.Id).
Execute()
if err != nil {
Expand All @@ -93,7 +93,7 @@ func runCRUD(client *kentikapi.Client) error {

func runGetAll(client *kentikapi.Client) error {
fmt.Println("### GET ALL")
getAllResp, httpResp, err := client.CloudExportAdminServiceApi.
getAllResp, httpResp, err := client.CloudExportAdminServiceAPI.
ExportList(context.Background()).
Execute()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions apiv6/examples/demos/cloud_export_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func createCloudExport(client *kentikapi.Client) string {
createReqPayload := *cloudexport.NewV202101beta1CreateCloudExportRequest()
createReqPayload.Export = export

createResp, _, err := client.CloudExportAdminServiceApi.
createResp, _, err := client.CloudExportAdminServiceAPI.
ExportCreate(context.Background()).
Body(createReqPayload).
Execute()
Expand All @@ -56,7 +56,7 @@ func createCloudExport(client *kentikapi.Client) string {
func getCloudExport(client *kentikapi.Client, id string) *cloudexport.V202101beta1CloudExport {
fmt.Printf("Retrieving cloud export of ID = %s\n", id)

getResp, _, err := client.CloudExportAdminServiceApi.
getResp, _, err := client.CloudExportAdminServiceAPI.
ExportGet(context.Background(), id).
Execute()
demos.ExitOnError(err)
Expand All @@ -70,7 +70,7 @@ func updateCloudExport(client *kentikapi.Client, export *cloudexport.V202101beta
updateReqPayload := *cloudexport.NewV202101beta1UpdateCloudExportRequest()
updateReqPayload.Export = export

updateResp, _, err := client.CloudExportAdminServiceApi.
updateResp, _, err := client.CloudExportAdminServiceAPI.
ExportUpdate(context.Background(), *export.Id).
Body(updateReqPayload).
Execute()
Expand All @@ -81,7 +81,7 @@ func updateCloudExport(client *kentikapi.Client, export *cloudexport.V202101beta

func deleteCloudExport(client *kentikapi.Client, id string) {
fmt.Printf("Deleting cloud export of ID = %s\n", id)
deleteResp, _, err := client.CloudExportAdminServiceApi.
deleteResp, _, err := client.CloudExportAdminServiceAPI.
ExportDelete(context.Background(), id).
Execute()
demos.ExitOnError(err)
Expand All @@ -91,7 +91,7 @@ func deleteCloudExport(client *kentikapi.Client, id string) {
}

func getAllCloudExports(client *kentikapi.Client) {
getAllResp, _, err := client.CloudExportAdminServiceApi.
getAllResp, _, err := client.CloudExportAdminServiceAPI.
ExportList(context.Background()).
Execute()
demos.ExitOnError(err)
Expand Down
2 changes: 1 addition & 1 deletion apiv6/examples/demos/retry_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func showRetryingOnMultipleCodes() error {
})

demos.Step("List synthetic agents")
result, _, err := c.SyntheticsAdminServiceApi.
result, _, err := c.SyntheticsAdminServiceAPI.
AgentsList(context.Background()).
Execute()

Expand Down
24 changes: 12 additions & 12 deletions apiv6/examples/synthetics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func runCRUDTest(client *kentikapi.Client) error {
createReqPayload := *synthetics.NewV202101beta1CreateTestRequest()
createReqPayload.SetTest(*test)

createResp, httpResp, err := client.SyntheticsAdminServiceApi.
createResp, httpResp, err := client.SyntheticsAdminServiceAPI.
TestCreate(context.Background()).
Body(createReqPayload).
Execute()
Expand All @@ -82,7 +82,7 @@ func runCRUDTest(client *kentikapi.Client) error {
setStatusReqPayload.Status = &status
setStatusReqPayload.Id = &testID

statusResp, httpResp, err := client.SyntheticsAdminServiceApi.
statusResp, httpResp, err := client.SyntheticsAdminServiceAPI.
TestStatusUpdate(context.Background(), testID).
Body(setStatusReqPayload).
Execute()
Expand All @@ -94,7 +94,7 @@ func runCRUDTest(client *kentikapi.Client) error {
fmt.Println()

fmt.Println("### GET TEST")
getReq := client.SyntheticsAdminServiceApi.TestGet(context.Background(), testID)
getReq := client.SyntheticsAdminServiceAPI.TestGet(context.Background(), testID)
getResp, httpResp, err := getReq.Execute()
if err != nil {
return fmt.Errorf("%v %v", err, httpResp)
Expand All @@ -112,7 +112,7 @@ func runCRUDTest(client *kentikapi.Client) error {
patchReqPayload.SetTest(*test)
patchReqPayload.SetMask("test.name")

patchResp, httpResp, err := client.SyntheticsAdminServiceApi.
patchResp, httpResp, err := client.SyntheticsAdminServiceAPI.
TestPatch(context.Background(), *test.Id).
Body(patchReqPayload).
Execute()
Expand All @@ -123,7 +123,7 @@ func runCRUDTest(client *kentikapi.Client) error {
fmt.Println()

fmt.Println("### DELETE TEST")
deleteReq := client.SyntheticsAdminServiceApi.TestDelete(context.Background(), testID)
deleteReq := client.SyntheticsAdminServiceAPI.TestDelete(context.Background(), testID)
deleteResp, httpResp, err := deleteReq.Execute()
if err != nil {
return fmt.Errorf("%v %v", err, httpResp)
Expand All @@ -138,7 +138,7 @@ func runCRUDTest(client *kentikapi.Client) error {
func runListTests(client *kentikapi.Client) error {
fmt.Println("### LIST TESTS")

getAllReq := client.SyntheticsAdminServiceApi.TestsList(context.Background())
getAllReq := client.SyntheticsAdminServiceAPI.TestsList(context.Background())
getAllResp, httpResp, err := getAllReq.Execute()
if err != nil {
return fmt.Errorf("%v %v", err, httpResp)
Expand Down Expand Up @@ -167,7 +167,7 @@ func runGetHealthForTests(client *kentikapi.Client, testIDs []string) error {
healthPayload.SetEndTime(time.Now())
healthPayload.SetIds(testIDs)

getHealthResp, httpResp, err := client.SyntheticsDataServiceApi.
getHealthResp, httpResp, err := client.SyntheticsDataServiceAPI.
GetHealthForTests(context.Background()).
Body(healthPayload).
Execute()
Expand Down Expand Up @@ -195,7 +195,7 @@ func runGetTraceForTest(client *kentikapi.Client, testID string) error {
tracePayload.SetStartTime(time.Now().Add(-time.Hour))
tracePayload.SetEndTime(time.Now())

getTraceResp, httpResp, err := client.SyntheticsDataServiceApi.
getTraceResp, httpResp, err := client.SyntheticsDataServiceAPI.
GetTraceForTest(context.Background(), testID).
Body(tracePayload).
Execute()
Expand Down Expand Up @@ -230,7 +230,7 @@ func runCRUDAgent(client *kentikapi.Client) error {
agentID := "1717"

fmt.Println("### GET AGENT")
getReq := client.SyntheticsAdminServiceApi.AgentGet(context.Background(), agentID)
getReq := client.SyntheticsAdminServiceAPI.AgentGet(context.Background(), agentID)
getResp, httpResp, err := getReq.Execute()
if err != nil {
return fmt.Errorf("%v %v", err, httpResp)
Expand All @@ -249,7 +249,7 @@ func runCRUDAgent(client *kentikapi.Client) error {
patchReqPayload.SetAgent(agent)
patchReqPayload.SetMask("agent.family")

patchResp, httpResp, err := client.SyntheticsAdminServiceApi.
patchResp, httpResp, err := client.SyntheticsAdminServiceAPI.
AgentPatch(context.Background(), agentID).
Body(patchReqPayload).
Execute()
Expand All @@ -261,7 +261,7 @@ func runCRUDAgent(client *kentikapi.Client) error {

// NOTE: as we can't create agents through the API - let's not delete them
// fmt.Println("### DELETE AGENT")
// deleteReq := client.SyntheticsAdminServiceApi.AgentDelete(context.Background(), agentID)
// deleteReq := client.SyntheticsAdminServiceAPI.AgentDelete(context.Background(), agentID)
// deleteResp, httpResp, err := deleteReq.Execute()
// if err != nil {
// return fmt.Errorf("%v %v", err, httpResp)
Expand All @@ -276,7 +276,7 @@ func runCRUDAgent(client *kentikapi.Client) error {
func runListAgents(client *kentikapi.Client) error {
fmt.Println("### LIST AGENTS")

getAllReq := client.SyntheticsAdminServiceApi.AgentsList(context.Background())
getAllReq := client.SyntheticsAdminServiceAPI.AgentsList(context.Background())
getAllResp, httpResp, err := getAllReq.Execute()
if err != nil {
return fmt.Errorf("%v %v", err, httpResp)
Expand Down
2 changes: 1 addition & 1 deletion apiv6/examples/synthetics/mesh_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getMeshTestResults(testID string) *[]synthetics.V202101beta1MeshResponse {
healthPayload.SetIds([]string{testID})
healthPayload.SetAugment(true) // if not set, returned Mesh pointer will be empty

getHealthResp, httpResp, err := client.SyntheticsDataServiceApi.
getHealthResp, httpResp, err := client.SyntheticsDataServiceAPI.
GetHealthForTests(context.Background()).
Body(healthPayload).
Execute()
Expand Down
13 changes: 6 additions & 7 deletions apiv6/kentikapi/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:revive,stylecheck // Changing Api to API forces changes in generated files
package kentikapi

import (
Expand All @@ -18,11 +17,11 @@ const (
// Client is the root object for manipulating all the Kentik API resources.
type Client struct {
// cloudexport
CloudExportAdminServiceApi *cloudexport.CloudExportAdminServiceApiService
CloudExportAdminServiceAPI *cloudexport.CloudExportAdminServiceApiService

// synthetics
SyntheticsAdminServiceApi *synthetics.SyntheticsAdminServiceApiService
SyntheticsDataServiceApi *synthetics.SyntheticsDataServiceApiService
SyntheticsAdminServiceAPI *synthetics.SyntheticsAdminServiceApiService
SyntheticsDataServiceAPI *synthetics.SyntheticsDataServiceApiService
}

// Config holds configuration of the Client.
Expand Down Expand Up @@ -54,9 +53,9 @@ func NewClient(c Config) *Client {
syntheticsClient := synthetics.NewAPIClient(makeSyntheticsConfig(c))

return &Client{
CloudExportAdminServiceApi: cloudexportClient.CloudExportAdminServiceApi,
SyntheticsAdminServiceApi: syntheticsClient.SyntheticsAdminServiceApi,
SyntheticsDataServiceApi: syntheticsClient.SyntheticsDataServiceApi,
CloudExportAdminServiceAPI: cloudexportClient.CloudExportAdminServiceApi,
SyntheticsAdminServiceAPI: syntheticsClient.SyntheticsAdminServiceApi,
SyntheticsDataServiceAPI: syntheticsClient.SyntheticsDataServiceApi,
}
}

Expand Down
9 changes: 2 additions & 7 deletions apiv6/kentikapi/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ const (
testAgentID = "968"
)

//nolint:errcheck // Conflict with defer Close() (additional info: https://github.com/kisielk/errcheck/issues/55)
func TestClient_PatchAgent(t *testing.T) {
t.Parallel()

tests := []struct {
name string
retryMax *int
Expand Down Expand Up @@ -164,10 +161,7 @@ func TestClient_PatchAgent(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

// arrange
h := newSpyHTTPHandler(t, tt.responses)
s := httptest.NewServer(h)
Expand All @@ -188,10 +182,11 @@ func TestClient_PatchAgent(t *testing.T) {
})

// act
result, httpResp, err := c.SyntheticsAdminServiceApi.
result, httpResp, err := c.SyntheticsAdminServiceAPI.
AgentPatch(context.Background(), testAgentID).
Body(tt.request).
Execute()
//nolint:errcheck // Additional info: https://github.com/kisielk/errcheck/issues/55
defer httpResp.Body.Close()

// assert
Expand Down
Loading

0 comments on commit c936e46

Please sign in to comment.