Skip to content

Commit 3425e9a

Browse files
committed
fix lint
1 parent 290de31 commit 3425e9a

14 files changed

Lines changed: 99 additions & 280 deletions

internal/cli/api.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ func truncateWithEllipsis(s string, max int) string {
3636
return s[:max-3] + "..."
3737
}
3838

39-
func min(a, b int) int {
40-
if a < b {
41-
return a
42-
}
43-
return b
44-
}
45-
4639
// computeTableLayout returns column widths for ID/Name/Path and whether to use a stacked fallback.
4740
func computeTableLayout(termWidth int) (idW, nameW, pathW int, stacked bool) {
4841
if termWidth < 20 {
@@ -254,8 +247,8 @@ After creation, you can:
254247
cmd.Flags().String("custom-domain", "", "Custom domain for the API")
255248
cmd.Flags().String("description", "", "API description")
256249

257-
cmd.MarkFlagRequired("name")
258-
cmd.MarkFlagRequired("upstream-url")
250+
_ = cmd.MarkFlagRequired("name")
251+
_ = cmd.MarkFlagRequired("upstream-url")
259252

260253
return cmd
261254
}
@@ -328,7 +321,7 @@ Examples:
328321
cmd.Flags().String("version-name", "", "Version name (defaults to info.version or v1)")
329322
cmd.Flags().Bool("set-default", true, "Set this version as the default")
330323

331-
cmd.MarkFlagRequired("file")
324+
_ = cmd.MarkFlagRequired("file")
332325

333326
return cmd
334327
}
@@ -544,7 +537,7 @@ func runInteractiveAPIList(c *client.Client, startPage int) error {
544537
return fmt.Errorf("failed to enable raw terminal mode: %w", err)
545538
}
546539
defer func() {
547-
term.Restore(int(os.Stdin.Fd()), oldState)
540+
_ = term.Restore(int(os.Stdin.Fd()), oldState)
548541
showCursor(os.Stderr)
549542
}()
550543

@@ -908,24 +901,6 @@ func stripExistingAPIID(oasData map[string]interface{}) map[string]interface{} {
908901
return oasData
909902
}
910903

911-
// extractAPIIDFromOAS extracts API ID from x-tyk-api-gateway.info.id
912-
func extractAPIIDFromOAS(oasData map[string]interface{}) (string, bool) {
913-
if xTyk, exists := oasData["x-tyk-api-gateway"]; exists {
914-
if xTykMap, ok := xTyk.(map[string]interface{}); ok {
915-
if info, exists := xTykMap["info"]; exists {
916-
if infoMap, ok := info.(map[string]interface{}); ok {
917-
if id, exists := infoMap["id"]; exists {
918-
if idStr, ok := id.(string); ok && idStr != "" {
919-
return idStr, true
920-
}
921-
}
922-
}
923-
}
924-
}
925-
}
926-
return "", false
927-
}
928-
929904
// runAPIApply implements the 'tyk api apply' command (declarative upsert)
930905
func runAPIApply(cmd *cobra.Command, args []string) error {
931906
// Get flags
@@ -1205,7 +1180,7 @@ func runAPIDelete(cmd *cobra.Command, args []string) error {
12051180
if !skipConfirmation {
12061181
fmt.Printf("Are you sure you want to delete API '%s' (%s)? [y/N]: ", apiID, api.Name)
12071182
var response string
1208-
fmt.Scanln(&response)
1183+
_, _ = fmt.Scanln(&response)
12091184
if strings.ToLower(response) != "y" && strings.ToLower(response) != "yes" {
12101185
fmt.Println("Delete operation cancelled")
12111186
return nil

internal/cli/api_get_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestAPIGet_WithOASOnly_JSON(t *testing.T) {
5858
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
5959
assert.Equal(t, "/api/apis/oas/test-api-id", r.URL.Path)
6060
w.Header().Set("Content-Type", "application/json")
61-
json.NewEncoder(w).Encode(mockOAS)
61+
_ = json.NewEncoder(w).Encode(mockOAS)
6262
}))
6363
defer server.Close()
6464

@@ -110,7 +110,7 @@ func TestAPIGet_WithOASOnly_YAML(t *testing.T) {
110110
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
111111
assert.Equal(t, "/api/apis/oas/test-api-id", r.URL.Path)
112112
w.Header().Set("Content-Type", "application/json")
113-
json.NewEncoder(w).Encode(mockOAS)
113+
_ = json.NewEncoder(w).Encode(mockOAS)
114114
}))
115115
defer server.Close()
116116

@@ -169,7 +169,7 @@ func TestAPIGet_WithoutOASOnly_ShowsFullOutput(t *testing.T) {
169169
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
170170
assert.Equal(t, "/api/apis/oas/test-api-id", r.URL.Path)
171171
w.Header().Set("Content-Type", "application/json")
172-
json.NewEncoder(w).Encode(mockOAS)
172+
_ = json.NewEncoder(w).Encode(mockOAS)
173173
}))
174174
defer server.Close()
175175

@@ -222,7 +222,7 @@ func TestAPIGet_WithOASOnly_HumanOutput_ShowsNoSummary(t *testing.T) {
222222

223223
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
224224
w.Header().Set("Content-Type", "application/json")
225-
json.NewEncoder(w).Encode(mockOAS)
225+
_ = json.NewEncoder(w).Encode(mockOAS)
226226
}))
227227
defer server.Close()
228228

@@ -276,7 +276,7 @@ func TestAPIGet_WithoutOASOnly_HumanOutput_ShowsSummary(t *testing.T) {
276276

277277
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
278278
w.Header().Set("Content-Type", "application/json")
279-
json.NewEncoder(w).Encode(mockOAS)
279+
_ = json.NewEncoder(w).Encode(mockOAS)
280280
}))
281281
defer server.Close()
282282

@@ -331,7 +331,7 @@ func TestAPIGet_WithoutOASOnly_HumanOutput_ShowsSummary(t *testing.T) {
331331
func TestAPIGet_ErrorHandling(t *testing.T) {
332332
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
333333
w.WriteHeader(http.StatusNotFound)
334-
w.Write([]byte("API not found"))
334+
_, _ = w.Write([]byte("API not found"))
335335
}))
336336
defer server.Close()
337337

internal/cli/api_import_update_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ func TestRunAPIImportOAS_WithFile(t *testing.T) {
120120
if r.Method == http.MethodPost && strings.Contains(r.URL.Path, "/api/apis/oas") {
121121
// Simulate API creation
122122
createResp := mockCreateAPIResponse()
123-
json.NewEncoder(w).Encode(createResp)
123+
_ = json.NewEncoder(w).Encode(createResp)
124124
} else if r.Method == http.MethodGet && strings.Contains(r.URL.Path, "/api/apis/oas/new-api-456") {
125125
// Simulate getting the created API details
126126
api := mockCreatedOASAPI()
127127
// Return the OAS document directly as the API endpoint does
128-
json.NewEncoder(w).Encode(api.OAS)
128+
_ = json.NewEncoder(w).Encode(api.OAS)
129129
}
130130
}))
131131
defer server.Close()
@@ -146,7 +146,7 @@ func TestRunAPIImportOAS_WithFile(t *testing.T) {
146146
cmd.SetContext(withOutputFormat(cmd.Context(), types.OutputJSON))
147147

148148
// Set flags
149-
cmd.Flags().Set("file", tmpFile)
149+
_ = cmd.Flags().Set("file", tmpFile)
150150

151151
// Execute command
152152
err := cmd.Execute()
@@ -184,8 +184,8 @@ func TestRunAPIImportOAS_BothInputs(t *testing.T) {
184184
cmd.SetContext(withConfig(context.Background(), config))
185185

186186
// Set both file and url flags
187-
cmd.Flags().Set("file", "/tmp/test.yaml")
188-
cmd.Flags().Set("url", "https://example.com/api.yaml")
187+
_ = cmd.Flags().Set("file", "/tmp/test.yaml")
188+
_ = cmd.Flags().Set("url", "https://example.com/api.yaml")
189189

190190
err := cmd.Execute()
191191

@@ -216,11 +216,11 @@ func TestRunAPIUpdateOAS_Success(t *testing.T) {
216216
// Simulate getting existing API
217217
existingAPI := mockCreatedOASAPI()
218218
existingAPI.ID = testAPIID
219-
json.NewEncoder(w).Encode(existingAPI.OAS)
219+
_ = json.NewEncoder(w).Encode(existingAPI.OAS)
220220
} else if r.Method == http.MethodPut && strings.Contains(r.URL.Path, testAPIID) {
221221
// Simulate API update
222222
updateResp := types.APIResponse{ID: testAPIID, Message: "Updated"}
223-
json.NewEncoder(w).Encode(updateResp)
223+
_ = json.NewEncoder(w).Encode(updateResp)
224224
}
225225
}))
226226
defer server.Close()
@@ -242,7 +242,7 @@ func TestRunAPIUpdateOAS_Success(t *testing.T) {
242242

243243
// Set args and flags
244244
cmd.SetArgs([]string{testAPIID})
245-
cmd.Flags().Set("file", tmpFile)
245+
_ = cmd.Flags().Set("file", tmpFile)
246246

247247
// Execute command
248248
err := cmd.Execute()
@@ -299,7 +299,7 @@ func TestRunAPIApply_PlainOASRejection(t *testing.T) {
299299
cmd.SetContext(withConfig(context.Background(), config))
300300

301301
// Set file flag
302-
cmd.Flags().Set("file", tmpFile)
302+
_ = cmd.Flags().Set("file", tmpFile)
303303

304304
// Execute command
305305
err := cmd.Execute()
@@ -326,12 +326,12 @@ func TestRunAPIApply_MissingIDCreatesAPI(t *testing.T) {
326326
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
327327
if r.Method == http.MethodPost && strings.Contains(r.URL.Path, "/api/apis/oas") {
328328
createResp := mockCreateAPIResponse()
329-
json.NewEncoder(w).Encode(createResp)
329+
_ = json.NewEncoder(w).Encode(createResp)
330330
return
331331
}
332332
if r.Method == http.MethodGet && strings.Contains(r.URL.Path, "/api/apis/oas/new-api-456") {
333333
api := mockCreatedOASAPI()
334-
json.NewEncoder(w).Encode(api.OAS)
334+
_ = json.NewEncoder(w).Encode(api.OAS)
335335
return
336336
}
337337
http.NotFound(w, r)
@@ -347,7 +347,7 @@ func TestRunAPIApply_MissingIDCreatesAPI(t *testing.T) {
347347
}
348348
cmd.SetContext(withConfig(context.Background(), config))
349349

350-
cmd.Flags().Set("file", tmpFile)
350+
_ = cmd.Flags().Set("file", tmpFile)
351351

352352
// Execute command: should succeed and create new API
353353
err := cmd.Execute()
@@ -382,7 +382,7 @@ func TestLoadOASFromURL_Success(t *testing.T) {
382382
testOAS := mockCleanOAS()
383383
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
384384
w.Header().Set("Content-Type", "application/json")
385-
json.NewEncoder(w).Encode(testOAS)
385+
_ = json.NewEncoder(w).Encode(testOAS)
386386
}))
387387
defer server.Close()
388388

@@ -413,7 +413,7 @@ func TestLoadOASFromURL_HTTPError(t *testing.T) {
413413
func TestLoadOASFromURL_InvalidJSON(t *testing.T) {
414414
// Create a test server that returns invalid JSON
415415
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
416-
w.Write([]byte("invalid json content"))
416+
_, _ = w.Write([]byte("invalid json content"))
417417
}))
418418
defer server.Close()
419419

internal/cli/api_interactive_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestAPIListInteractiveFlag(t *testing.T) {
2323

2424
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2525
assert.Equal(t, "/api/apis/oas", r.URL.Path)
26-
json.NewEncoder(w).Encode(types.OASAPIListResponse{
26+
_ = json.NewEncoder(w).Encode(types.OASAPIListResponse{
2727
APIResponse: types.APIResponse{Status: "success"},
2828
APIs: mockAPIs,
2929
})
@@ -257,7 +257,7 @@ func TestAPIListWithRealEndpoint(t *testing.T) {
257257

258258
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
259259
assert.Equal(t, "/api/apis", r.URL.Path)
260-
json.NewEncoder(w).Encode(dashboardResponse)
260+
_ = json.NewEncoder(w).Encode(dashboardResponse)
261261
}))
262262
defer server.Close()
263263

internal/cli/api_list_test.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,14 @@ import (
88
"os"
99
"testing"
1010

11-
"github.com/spf13/cobra"
1211
"github.com/stretchr/testify/require"
1312
"github.com/tyktech/tyk-cli/pkg/types"
1413
)
1514

16-
// Helper to prepare root with config context
17-
func prepareRootWithEnv(t *testing.T, dashURL string) *cobra.Command {
18-
t.Helper()
19-
root := NewRootCommand("test", "commit", "time")
20-
// Find 'api list'
21-
listCmd, _, err := root.Find([]string{"api", "list"})
22-
require.NoError(t, err)
23-
24-
// Inject config into context
25-
cfg := &types.Config{
26-
DefaultEnvironment: "test",
27-
Environments: map[string]*types.Environment{
28-
"test": {Name: "test", DashboardURL: dashURL, AuthToken: "token", OrgID: "org"},
29-
},
30-
}
31-
listCmd.SetContext(withConfig(context.Background(), cfg))
32-
listCmd.SetContext(withOutputFormat(listCmd.Context(), types.OutputHuman))
33-
return root
34-
}
35-
3615
func TestAPIList_JSONOutput(t *testing.T) {
3716
mockAPIs := []*types.OASAPI{{ID: "id1", Name: "Name1"}}
3817
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39-
json.NewEncoder(w).Encode(types.OASAPIListResponse{APIs: mockAPIs})
18+
_ = json.NewEncoder(w).Encode(types.OASAPIListResponse{APIs: mockAPIs})
4019
}))
4120
defer server.Close()
4221

@@ -58,7 +37,7 @@ func TestAPIList_JSONOutput(t *testing.T) {
5837

5938
func TestAPIList_HumanOutput_NoAPIs(t *testing.T) {
6039
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
61-
json.NewEncoder(w).Encode(types.OASAPIListResponse{APIs: []*types.OASAPI{}})
40+
_ = json.NewEncoder(w).Encode(types.OASAPIListResponse{APIs: []*types.OASAPI{}})
6241
}))
6342
defer server.Close()
6443

internal/cli/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ Examples:
9797
cmd.Flags().String("org-id", "", "Organization ID")
9898
cmd.Flags().Bool("set-default", false, "Set this environment as the default")
9999

100-
cmd.MarkFlagRequired("dashboard-url")
101-
cmd.MarkFlagRequired("auth-token")
102-
cmd.MarkFlagRequired("org-id")
100+
_ = cmd.MarkFlagRequired("dashboard-url")
101+
_ = cmd.MarkFlagRequired("auth-token")
102+
_ = cmd.MarkFlagRequired("org-id")
103103

104104
return cmd
105105
}

0 commit comments

Comments
 (0)