Skip to content

Commit

Permalink
deps: bump to use go1.21 and fix golangci-lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Rui Chen <rui@chenrui.dev>
  • Loading branch information
chenrui333 committed Aug 21, 2023
1 parent 39dee2f commit 44b38c0
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
version: v1.54.2
args: --timeout=5m
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fail-fast: false
matrix:
terraform:
- 1.5.0
- 1.5.5
- 1.4.6
- 1.3.9
- 0.12.31
Expand Down
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20
1.21
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG TERRAFORM_VERSION=latest
FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform

FROM golang:1.20-alpine3.17
FROM golang:1.21-alpine3.18
RUN apk --no-cache add make git bash
COPY --from=terraform /bin/terraform /usr/local/bin/
WORKDIR /work
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ https://github.com/minamijoyo/tfmigrate/releases

### Source

If you have Go 1.20+ development environment:
If you have Go 1.21+ development environment:

```
$ git clone https://github.com/minamijoyo/tfmigrate
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/minamijoyo/tfmigrate

go 1.20
go 1.21

require (
cloud.google.com/go/storage v1.25.0
Expand Down
4 changes: 3 additions & 1 deletion history/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ func TestControllerAddRecord(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
currentTC := tc

c := &Controller{
migrations: tc.migrations,
history: tc.history,
}

c.AddRecord(tc.filename, tc.migrationType, tc.name, &tc.appliedAt)
c.AddRecord(tc.filename, tc.migrationType, currentTC.name, &currentTC.appliedAt)
got := tc.history
if diff := cmp.Diff(got, tc.want, cmp.AllowUnexported(got)); diff != "" {
t.Errorf("got = %#v, want = %#v, diff = %s", got, tc.want, diff)
Expand Down
4 changes: 2 additions & 2 deletions storage/gcs/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type mockClient struct {
err error
}

func (c *mockClient) Read(ctx context.Context) ([]byte, error) {
func (c *mockClient) Read(_ context.Context) ([]byte, error) {
return c.dataToRead, c.err
}

func (c *mockClient) Write(ctx context.Context, b []byte) error {
func (c *mockClient) Write(_ context.Context, _ []byte) error {
return c.err
}

Expand Down
4 changes: 2 additions & 2 deletions storage/local/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewStorage(config *Config) (*Storage, error) {
}

// Write writes migration history data to storage.
func (s *Storage) Write(ctx context.Context, b []byte) error {
func (s *Storage) Write(_ context.Context, b []byte) error {
// nolint gosec
// G306: Expect WriteFile permissions to be 0600 or less
// We ignore it because a history file doesn't contains sensitive data.
Expand All @@ -38,7 +38,7 @@ func (s *Storage) Write(ctx context.Context, b []byte) error {
// Read reads migration history data from storage.
// If the key does not exist, it is assumed to be uninitialized and returns
// an empty array instead of an error.
func (s *Storage) Read(ctx context.Context) ([]byte, error) {
func (s *Storage) Read(_ context.Context) ([]byte, error) {
if _, err := os.Stat(s.config.Path); os.IsNotExist(err) {
// If the key does not exist
return []byte{}, nil
Expand Down
4 changes: 2 additions & 2 deletions storage/mock/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *Storage) Data() string {
}

// Write writes migration history data to storage.
func (s *Storage) Write(ctx context.Context, b []byte) error {
func (s *Storage) Write(_ context.Context, b []byte) error {
if s.config.WriteError {
return fmt.Errorf("failed to write mock storage: writeError = %t", s.config.WriteError)
}
Expand All @@ -42,7 +42,7 @@ func (s *Storage) Write(ctx context.Context, b []byte) error {
}

// Read reads migration history data from storage.
func (s *Storage) Read(ctx context.Context) ([]byte, error) {
func (s *Storage) Read(_ context.Context) ([]byte, error) {
if s.config.ReadError {
return nil, fmt.Errorf("failed to read mock storage: readError = %t", s.config.ReadError)
}
Expand Down
4 changes: 2 additions & 2 deletions storage/s3/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type mockClient struct {
}

// PutObjectWithContext returns a mocked response.
func (c *mockClient) PutObjectWithContext(ctx aws.Context, input *s3.PutObjectInput, opts ...request.Option) (*s3.PutObjectOutput, error) {
func (c *mockClient) PutObjectWithContext(_ aws.Context, _ *s3.PutObjectInput, _ ...request.Option) (*s3.PutObjectOutput, error) {
return c.putOutput, c.err
}

// GetObjectWithContext returns a mocked response.
func (c *mockClient) GetObjectWithContext(ctx aws.Context, input *s3.GetObjectInput, opts ...request.Option) (*s3.GetObjectOutput, error) {
func (c *mockClient) GetObjectWithContext(_ aws.Context, _ *s3.GetObjectInput, _ ...request.Option) (*s3.GetObjectOutput, error) {
return c.getOutput, c.err
}

Expand Down
2 changes: 1 addition & 1 deletion tfexec/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func mockEcho(args ...string) int {
return 0
}

func mockFalse(args ...string) int {
func mockFalse(_ ...string) int {
return 1
}

Expand Down
4 changes: 2 additions & 2 deletions tfexec/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewMockExecutor(mockCommands []*mockCommand) Executor {
}

// NewCommandContext builds and returns an instance of Command.
func (e *mockExecutor) NewCommandContext(ctx context.Context, name string, args ...string) (Command, error) {
func (e *mockExecutor) NewCommandContext(_ context.Context, name string, args ...string) (Command, error) {
cmd := e.mockCommands[e.newCommnadContextCalls]
e.newCommnadContextCalls++
// store called args to pass runFunc callback.
Expand Down Expand Up @@ -70,7 +70,7 @@ func (e *mockExecutor) Dir() string {
}

// AppendEnv appends an environment variable.
func (e *mockExecutor) AppendEnv(key string, value string) {
func (e *mockExecutor) AppendEnv(_ string, _ string) {
// no op.
}

Expand Down
4 changes: 2 additions & 2 deletions tfmigrate/mock_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MockMigratorConfig struct {
var _ MigratorConfig = (*MockMigratorConfig)(nil)

// NewMigrator returns a new instance of MockMigrator.
func (c *MockMigratorConfig) NewMigrator(o *MigratorOption) (Migrator, error) {
func (c *MockMigratorConfig) NewMigrator(_ *MigratorOption) (Migrator, error) {
return NewMockMigrator(c.PlanError, c.ApplyError), nil
}

Expand All @@ -45,7 +45,7 @@ func NewMockMigrator(planError bool, applyError bool) *MockMigrator {

// plan computes a new state by applying state migration operations to a temporary state.
// It does nothing, but can return an error.
func (m *MockMigrator) plan(ctx context.Context) (*tfexec.State, error) {
func (m *MockMigrator) plan(_ context.Context) (*tfexec.State, error) {
if m.planError {
return nil, fmt.Errorf("failed to plan mock migrator: planError = %t", m.planError)
}
Expand Down

0 comments on commit 44b38c0

Please sign in to comment.