Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go.mod update #120

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 .
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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/incu6us/goimports-reviser/v3

go 1.18
go 1.20

require (
github.com/stretchr/testify v1.6.1
Expand Down
10 changes: 8 additions & 2 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 26 additions & 6 deletions helper/helper_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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",
Expand All @@ -31,6 +34,7 @@ func TestDetermineProjectName(t *testing.T) {
require.NoError(t, err)
return dir
}(),
option: OSGetwdOption,
},
want: "github.com/incu6us/goimports-reviser/v3",
},
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions pkg/std/package_list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.