From 58a2a4078db2397342c0282cbc3fec04de135d77 Mon Sep 17 00:00:00 2001 From: Vyacheslav Pryimak Date: Wed, 16 Aug 2023 16:39:15 +0300 Subject: [PATCH] go.mod update (#120) * go.mod update --- .github/workflows/go.yml | 8 +++++--- .github/workflows/release.yml | 4 ++-- Makefile | 4 ++++ go.mod | 2 +- helper/helper.go | 10 ++++++++-- helper/helper_test.go | 32 ++++++++++++++++++++++++++------ main.go | 2 +- pkg/std/package_list.go | 2 ++ 8 files changed, 49 insertions(+), 15 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index db2e73b..642268f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,12 +8,11 @@ on: - "*" jobs: - build: strategy: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] - go-version: [ 1.18.x, oldstable, stable ] + go-version: [ 1.20.x, oldstable, stable ] runs-on: ${{ matrix.os }} steps: @@ -33,9 +32,12 @@ jobs: run: go test -race -cover -coverprofile=coverage -covermode=atomic ./... - name: Coverage - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: file: ./coverage + flags: unittests + fail_ci_if_error: false + verbose: true - name: Build run: go build -v . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1b80f1..a5dbdb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,10 +15,10 @@ jobs: - name: Unshallow run: git fetch --prune --unshallow - - name: Set up Go 1.18 + - name: Set up Go 1.20 uses: actions/setup-go@v1 with: - go-version: 1.18 + go-version: 1.20 id: go - name: Set Envs diff --git a/Makefile b/Makefile index 775ce59..6a582f6 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,10 @@ build-lint-linux-amd64: build-lint-linux-arm64: GOOS=linux GOARCH=arm64 go build -tags linter,osusergo -o bin/linux-arm64/goimportsreviserlint ./linter +.PHONY: build-macos-amd64 +build-macos-amd64: + GOOS=darwin GOARCH=amd64 go build -o bin/macos-amd64/goimports-reviser . + .PHONY: update-std-package-list update-std-package-list: @go run -tags gen github.com/incu6us/goimports-reviser/v3/pkg/std/gen diff --git a/go.mod b/go.mod index 5b874a5..c260f41 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/incu6us/goimports-reviser/v3 -go 1.18 +go 1.20 require ( github.com/stretchr/testify v1.6.1 diff --git a/helper/helper.go b/helper/helper.go index 649b6c7..c51c692 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -7,10 +7,16 @@ import ( "github.com/incu6us/goimports-reviser/v3/reviser" ) -func DetermineProjectName(projectName, filePath string) (string, error) { +type Option func() (string, error) + +func OSGetwdOption() (string, error) { + return os.Getwd() +} + +func DetermineProjectName(projectName, filePath string, option Option) (string, error) { if filePath == reviser.StandardInput { var err error - filePath, err = os.Getwd() + filePath, err = option() if err != nil { return "", err } diff --git a/helper/helper_test.go b/helper/helper_test.go index e267c61..30f2f14 100644 --- a/helper/helper_test.go +++ b/helper/helper_test.go @@ -1,13 +1,14 @@ package helper import ( + "errors" "os" "testing" - "github.com/incu6us/goimports-reviser/v3/reviser" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/incu6us/goimports-reviser/v3/reviser" ) func TestDetermineProjectName(t *testing.T) { @@ -16,11 +17,13 @@ func TestDetermineProjectName(t *testing.T) { type args struct { projectName string filePath string + option Option } tests := []struct { - name string - args args - want string + name string + args args + want string + wantErr bool }{ { name: "success with manual filepath", @@ -31,6 +34,7 @@ func TestDetermineProjectName(t *testing.T) { require.NoError(t, err) return dir }(), + option: OSGetwdOption, }, want: "github.com/incu6us/goimports-reviser/v3", }, @@ -39,16 +43,32 @@ func TestDetermineProjectName(t *testing.T) { args: args{ projectName: "", filePath: reviser.StandardInput, + option: OSGetwdOption, }, want: "github.com/incu6us/goimports-reviser/v3", }, + { + name: "fail with manual filepath", + args: args{ + projectName: "", + filePath: reviser.StandardInput, + option: func() (string, error) { + return "", errors.New("some error") + }, + }, + wantErr: true, + }, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - got, err := DetermineProjectName(tt.args.projectName, tt.args.filePath) + got, err := DetermineProjectName(tt.args.projectName, tt.args.filePath, tt.args.option) + if tt.wantErr { + require.Error(t, err) + return + } require.NoError(t, err) assert.Equal(t, tt.want, got) }) diff --git a/main.go b/main.go index 9a20bd1..5e5222c 100644 --- a/main.go +++ b/main.go @@ -257,7 +257,7 @@ func main() { options = append(options, reviser.WithImportsOrder(order)) } - originProjectName, err := helper.DetermineProjectName(projectName, originPath) + originProjectName, err := helper.DetermineProjectName(projectName, originPath, helper.OSGetwdOption) if err != nil { fmt.Printf("%s\n\n", err) printUsage() diff --git a/pkg/std/package_list.go b/pkg/std/package_list.go index cdee053..7d6c41a 100644 --- a/pkg/std/package_list.go +++ b/pkg/std/package_list.go @@ -230,11 +230,13 @@ var StdPackages = map[string]struct{}{ "runtime/debug": {}, "runtime/internal/atomic": {}, "runtime/internal/math": {}, + "runtime/internal/startlinetest": {}, "runtime/internal/sys": {}, "runtime/internal/wasitest": {}, "runtime/metrics": {}, "runtime/pprof": {}, "runtime/race": {}, + "runtime/race/internal/amd64v1": {}, "runtime/trace": {}, "slices": {}, "sort": {},