Skip to content

Commit d223af3

Browse files
committed
feat(alb): fix linter issues
1 parent e5854f8 commit d223af3

File tree

10 files changed

+17
-36
lines changed

10 files changed

+17
-36
lines changed

internal/cmd/beta/alb/create/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClie
138138
return req.CreateLoadBalancerPayload(payload), nil
139139
}
140140

141-
func readPayload(ctx context.Context, model *inputModel) (payload alb.CreateLoadBalancerPayload, err error) {
141+
func readPayload(_ context.Context, model *inputModel) (payload alb.CreateLoadBalancerPayload, err error) {
142142
if model.Configuration == nil {
143143
return payload, fmt.Errorf("no configuration file defined")
144144
}
145145
file, err := os.Open(*model.Configuration)
146146
if err != nil {
147147
return payload, fmt.Errorf("cannot open configuration file %q: %w", *model.Configuration, err)
148148
}
149-
defer file.Close()
149+
defer file.Close() // nolint:errcheck // at this point close errors are not relevant anymore
150150

151151
if strings.HasSuffix(*model.Configuration, ".yaml") {
152152
decoder := yaml.NewDecoder(bufio.NewReader(file), yaml.UseJSONUnmarshaler())
@@ -159,7 +159,7 @@ func readPayload(ctx context.Context, model *inputModel) (payload alb.CreateLoad
159159
return payload, fmt.Errorf("cannot deserialize json configuration from %q: %w", *model.Configuration, err)
160160
}
161161
} else {
162-
return payload, fmt.Errorf("cannot determine configuration fileformat of %q by extension. Must be '.json' or '.yaml'", err)
162+
return payload, fmt.Errorf("cannot determine configuration fileformat of %q by extension. Must be '.json' or '.yaml'", *model.Configuration)
163163
}
164164

165165
return payload, nil

internal/cmd/beta/alb/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
6363
return cmd
6464
}
6565

66-
func configureFlags(cmd *cobra.Command) {
66+
func configureFlags(_ *cobra.Command) {
6767
}
6868

6969
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

internal/cmd/beta/alb/describe/describe.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,15 @@ func NewCmd(p *print.Printer) *cobra.Command {
6161
}
6262

6363
if loadbalancer := resp; loadbalancer != nil {
64-
return outputResult(p, model.OutputFormat, *loadbalancer)
64+
return outputResult(p, model.OutputFormat, loadbalancer)
6565
}
6666
p.Outputln("No load balancer found.")
6767
return nil
6868
},
6969
}
70-
configureFlags(cmd)
7170
return cmd
7271
}
7372

74-
func configureFlags(cmd *cobra.Command) {
75-
}
76-
7773
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
7874
globalFlags := globalflags.Parse(p, cmd)
7975

@@ -99,7 +95,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClie
9995
return apiClient.GetLoadBalancer(ctx, model.ProjectId, model.Region, model.Name)
10096
}
10197

102-
func outputResult(p *print.Printer, outputFormat string, response alb.LoadBalancer) error {
98+
func outputResult(p *print.Printer, outputFormat string, response *alb.LoadBalancer) error {
10399
switch outputFormat {
104100
case print.JSONOutputFormat:
105101
details, err := json.MarshalIndent(response, "", " ")

internal/cmd/beta/alb/describe/describe_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func Test_outputResult(t *testing.T) {
195195
type args struct {
196196
outputFormat string
197197
showOnlyPublicKey bool
198-
response alb.LoadBalancer
198+
response *alb.LoadBalancer
199199
}
200200
tests := []struct {
201201
name string
@@ -207,7 +207,7 @@ func Test_outputResult(t *testing.T) {
207207
args: args{
208208
outputFormat: "",
209209
showOnlyPublicKey: false,
210-
response: alb.LoadBalancer{},
210+
response: &alb.LoadBalancer{},
211211
},
212212
wantErr: false,
213213
},

internal/cmd/beta/alb/template/template.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func NewCmd(p *print.Printer) *cobra.Command {
7171
} else {
7272
return fmt.Errorf("invalid format %q defined. Must be 'json' or 'yaml'", *model.Format)
7373
}
74-
io.Copy(os.Stdout, reader)
74+
if _, err := io.Copy(os.Stdout, reader); err != nil {
75+
return fmt.Errorf("cannot write output: %w", err)
76+
}
7577

7678
_, _ = ctx, model
7779

internal/cmd/beta/alb/template/template_test.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
package template
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
87
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
98

109
"github.com/google/go-cmp/cmp"
1110
"github.com/google/uuid"
12-
"github.com/stackitcloud/stackit-sdk-go/services/alb"
1311
)
1412

15-
type testCtxKey struct{}
16-
1713
var (
18-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
19-
testClient = &alb.APIClient{}
20-
testProjectId = uuid.NewString()
21-
testRegion = "eu01"
22-
testLimit int64 = 10
14+
testProjectId = uuid.NewString()
15+
testRegion = "eu01"
2316
)
2417

2518
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
@@ -43,14 +36,6 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4336
return model
4437
}
4538

46-
func fixtureRequest(mods ...func(request *alb.ApiListLoadBalancersRequest)) alb.ApiListLoadBalancersRequest {
47-
request := testClient.ListLoadBalancers(context.Background(), testProjectId, testRegion)
48-
for _, mod := range mods {
49-
mod(&request)
50-
}
51-
return request
52-
}
53-
5439
func TestParseInput(t *testing.T) {
5540
tests := []struct {
5641
description string

internal/cmd/beta/alb/update/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClie
138138
return req.UpdateLoadBalancerPayload(payload), nil
139139
}
140140

141-
func readPayload(ctx context.Context, model *inputModel) (payload alb.UpdateLoadBalancerPayload, err error) {
141+
func readPayload(_ context.Context, model *inputModel) (payload alb.UpdateLoadBalancerPayload, err error) {
142142
if model.Configuration == nil {
143143
return payload, fmt.Errorf("no configuration file defined")
144144
}
145145
file, err := os.Open(*model.Configuration)
146146
if err != nil {
147147
return payload, fmt.Errorf("cannot open configuration file %q: %w", *model.Configuration, err)
148148
}
149-
defer file.Close()
149+
defer file.Close() // nolint:errcheck // at this point close errors are not relevant anymore
150150

151151
if strings.HasSuffix(*model.Configuration, ".yaml") {
152152
decoder := yaml.NewDecoder(bufio.NewReader(file), yaml.UseJSONUnmarshaler())
@@ -159,7 +159,7 @@ func readPayload(ctx context.Context, model *inputModel) (payload alb.UpdateLoad
159159
return payload, fmt.Errorf("cannot deserialize json configuration from %q: %w", *model.Configuration, err)
160160
}
161161
} else {
162-
return payload, fmt.Errorf("cannot determine configuration fileformat of %q by extension. Must be '.json' or '.yaml'", err)
162+
return payload, fmt.Errorf("cannot determine configuration fileformat of %q by extension. Must be '.json' or '.yaml'", *model.Configuration)
163163
}
164164

165165
return payload, nil

internal/cmd/beta/beta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package beta
33
import (
44
"fmt"
55

6-
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/sqlserverflex"
76
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/alb"
7+
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/sqlserverflex"
88
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
99
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1010
"github.com/stackitcloud/stackit-cli/internal/pkg/print"

internal/pkg/services/alb/utils/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ package utils
22

33
type AlbClient interface {
44
}
5-

internal/pkg/services/alb/utils/utils_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ package utils
22

33
type AlbClientMocked struct {
44
}
5-

0 commit comments

Comments
 (0)