Skip to content

Commit

Permalink
up: update deps, remote dep stretchr/testify
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 17, 2022
1 parent 1c3506b commit 8eb2535
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_version: [1.18, 1.15, 1.16, 1.17]
go_version: [1.18, 1.19, 1.16, 1.17]

steps:
- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion chlog/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/gookit/gitw/chlog"
"github.com/stretchr/testify/assert"
"github.com/gookit/goutil/testutil/assert"
)

func TestKeywordsFilter(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion cmd_quick.go

This file was deleted.

6 changes: 3 additions & 3 deletions cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/gookit/gitw"
"github.com/gookit/goutil/dump"
"github.com/stretchr/testify/assert"
"github.com/gookit/goutil/testutil/assert"
)

func TestTags(t *testing.T) {
ts, err := gitw.Tags()
assert.NoError(t, err)
assert.NoErr(t, err)
dump.P(ts)

ts, err = gitw.Tags("-n", "--sort=-version:refname")
assert.NoError(t, err)
assert.NoErr(t, err)
dump.P(ts)
}
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
module github.com/gookit/gitw

go 1.15
go 1.18

require (
github.com/gookit/color v1.5.2
github.com/gookit/goutil v0.5.15
github.com/gookit/slog v0.3.3
github.com/stretchr/testify v1.8.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/gookit/gsr v0.0.7 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.8 // indirect
)
90 changes: 45 additions & 45 deletions info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,92 @@ import (

"github.com/gookit/gitw"
"github.com/gookit/goutil/dump"
"github.com/stretchr/testify/assert"
"github.com/gookit/goutil/testutil/assert"
)

func TestNewRemoteInfo(t *testing.T) {
URL := "https://github.com/gookit/gitw"

rt, err := gitw.NewRemoteInfo("origin", URL, gitw.RemoteTypePush)
assert.NoError(t, err)
assert.NoErr(t, err)
assert.True(t, rt.Valid())
assert.False(t, rt.Invalid())
assert.Equal(t, "origin", rt.Name)
assert.Equal(t, gitw.RemoteTypePush, rt.Type)
assert.Equal(t, "github.com", rt.Host)
assert.Equal(t, "gookit/gitw", rt.RepoPath())
assert.Equal(t, gitw.SchemeHTTPS, rt.Scheme)
assert.Equal(t, gitw.ProtoHTTP, rt.Proto)
assert.Equal(t, rt.URL, rt.RawURLOfHTTP())
assert.Eq(t, "origin", rt.Name)
assert.Eq(t, gitw.RemoteTypePush, rt.Type)
assert.Eq(t, "github.com", rt.Host)
assert.Eq(t, "gookit/gitw", rt.RepoPath())
assert.Eq(t, gitw.SchemeHTTPS, rt.Scheme)
assert.Eq(t, gitw.ProtoHTTP, rt.Proto)
assert.Eq(t, rt.URL, rt.RawURLOfHTTP())

URL = "[email protected]:gookit/gitw.git"
rt, err = gitw.NewRemoteInfo("origin", URL, gitw.RemoteTypePush)
assert.NoError(t, err)
assert.Equal(t, "github.com", rt.Host)
assert.Equal(t, "gookit/gitw", rt.Path())
assert.Equal(t, gitw.SchemeGIT, rt.Scheme)
assert.Equal(t, gitw.ProtoSSH, rt.Proto)
assert.Equal(t, "https://github.com/gookit/gitw", rt.RawURLOfHTTP())
assert.NoErr(t, err)
assert.Eq(t, "github.com", rt.Host)
assert.Eq(t, "gookit/gitw", rt.Path())
assert.Eq(t, gitw.SchemeGIT, rt.Scheme)
assert.Eq(t, gitw.ProtoSSH, rt.Proto)
assert.Eq(t, "https://github.com/gookit/gitw", rt.RawURLOfHTTP())
}

func TestParseBranchLine_simple(t *testing.T) {
info, err := gitw.ParseBranchLine("* ", false)
assert.Error(t, err)
assert.Err(t, err)

info, err = gitw.ParseBranchLine("* (HEAD)", false)
assert.Error(t, err)
assert.Err(t, err)

info, err = gitw.ParseBranchLine("* fea/new_br001", false)
assert.NoError(t, err)
assert.NoErr(t, err)

assert.True(t, info.Current)
assert.True(t, info.IsValid())
assert.False(t, info.IsRemoted())
assert.Equal(t, "", info.Remote)
assert.Equal(t, "fea/new_br001", info.Name)
assert.Equal(t, "fea/new_br001", info.Short)
assert.Eq(t, "", info.Remote)
assert.Eq(t, "fea/new_br001", info.Name)
assert.Eq(t, "fea/new_br001", info.Short)

info, err = gitw.ParseBranchLine(" remotes/source/my_new_br ", false)
assert.NoError(t, err)
assert.NoErr(t, err)

assert.False(t, info.Current)
assert.True(t, info.IsValid())
assert.True(t, info.IsRemoted())
assert.Equal(t, "source", info.Remote)
assert.Equal(t, "remotes/source/my_new_br", info.Name)
assert.Equal(t, "my_new_br", info.Short)
assert.Eq(t, "source", info.Remote)
assert.Eq(t, "remotes/source/my_new_br", info.Name)
assert.Eq(t, "my_new_br", info.Short)
}

func TestParseBranchLine_verbose(t *testing.T) {
info, err := gitw.ParseBranchLine("* fea/new_br001 73j824d the message 001", true)
assert.NoError(t, err)
assert.NoErr(t, err)

assert.True(t, info.Current)
assert.True(t, info.IsValid())
assert.False(t, info.IsRemoted())
assert.Equal(t, "", info.Remote)
assert.Equal(t, "fea/new_br001", info.Name)
assert.Equal(t, "fea/new_br001", info.Short)
assert.Equal(t, "73j824d", info.Hash)
assert.Equal(t, "the message 001", info.HashMsg)
assert.Eq(t, "", info.Remote)
assert.Eq(t, "fea/new_br001", info.Name)
assert.Eq(t, "fea/new_br001", info.Short)
assert.Eq(t, "73j824d", info.Hash)
assert.Eq(t, "the message 001", info.HashMsg)

info, err = gitw.ParseBranchLine(" remotes/source/my_new_br 6fb8dcd the message 003 ", true)
assert.NoError(t, err)
assert.NoErr(t, err)
dump.P(info)

assert.False(t, info.Current)
assert.True(t, info.IsValid())
assert.True(t, info.IsRemoted())
assert.Equal(t, "source", info.Remote)
assert.Equal(t, "remotes/source/my_new_br", info.Name)
assert.Equal(t, "my_new_br", info.Short)
assert.Equal(t, "6fb8dcd", info.Hash)
assert.Equal(t, "the message 003", info.HashMsg)
assert.Eq(t, "source", info.Remote)
assert.Eq(t, "remotes/source/my_new_br", info.Name)
assert.Eq(t, "my_new_br", info.Short)
assert.Eq(t, "6fb8dcd", info.Hash)
assert.Eq(t, "the message 003", info.HashMsg)

info, err = gitw.ParseBranchLine("* (头指针在 v0.2.3 分离) 3c08adf chore: update readme add branch info docs", true)
assert.Error(t, err)
assert.Err(t, err)
info, err = gitw.ParseBranchLine("* (HEAD detached at pull/29/merge) 62f3455 Merge cfc79b748e176c1c9e266c8bc413c87fe974acef into c9503c2aef993a2cf582d90c137deda53c9bca68", true)
assert.Error(t, err)
assert.Err(t, err)
}

func TestBranchInfo_parse_simple(t *testing.T) {
Expand All @@ -106,11 +106,11 @@ func TestBranchInfo_parse_simple(t *testing.T) {
bis.Parse()
// dump.P(bis)

assert.NoError(t, bis.LastErr())
assert.NoErr(t, bis.LastErr())
assert.NotEmpty(t, bis.Current())
assert.NotEmpty(t, bis.Locales())
assert.NotEmpty(t, bis.Remotes(""))
assert.Equal(t, "master", bis.Current().Name)
assert.Eq(t, "master", bis.Current().Name)
}

func TestBranchInfo_parse_invalid(t *testing.T) {
Expand All @@ -124,7 +124,7 @@ func TestBranchInfo_parse_invalid(t *testing.T) {
bis.Parse()
// dump.P(bis)

assert.Error(t, bis.LastErr())
assert.Err(t, bis.LastErr())
assert.Nil(t, bis.Current())
assert.NotEmpty(t, bis.Locales())
assert.NotEmpty(t, bis.Remotes("origin"))
Expand All @@ -144,11 +144,11 @@ func TestBranchInfo_parse_verbose(t *testing.T) {
bis.Parse()
// dump.P(bis)

assert.NoError(t, bis.LastErr())
assert.NoErr(t, bis.LastErr())
assert.NotEmpty(t, bis.Current())
assert.NotEmpty(t, bis.Locales())
assert.NotEmpty(t, bis.Remotes(""))
assert.Equal(t, "master", bis.Current().Name)
assert.Eq(t, "master", bis.Current().Name)

// search
rets := bis.Search("new", gitw.BrSearchLocal)
Expand All @@ -165,5 +165,5 @@ func TestBranchInfo_parse_verbose(t *testing.T) {
assert.NotEmpty(t, rets)
assert.Len(t, rets, 1)
assert.True(t, rets[0].IsRemoted())
assert.Equal(t, "origin", rets[0].Remote)
assert.Eq(t, "origin", rets[0].Remote)
}
26 changes: 13 additions & 13 deletions repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/gookit/gitw"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/sysutil"
"github.com/gookit/goutil/testutil/assert"
"github.com/gookit/slog"
"github.com/stretchr/testify/assert"
)

var repo = gitw.NewRepo("./").WithFn(func(r *gitw.Repo) {
Expand All @@ -23,7 +23,7 @@ func TestRepo_RemoteInfos(t *testing.T) {
rs := repo.AllRemoteInfos()
dump.P(rs)

assert.NoError(t, repo.Err())
assert.NoErr(t, repo.Err())
assert.NotEmpty(t, rs)

assert.True(t, repo.HasRemote(gitw.DefaultRemoteName))
Expand All @@ -37,18 +37,18 @@ func TestRepo_DefaultRemoteInfo(t *testing.T) {
assert.NotEmpty(t, rt)
assert.True(t, rt.Valid())
assert.False(t, rt.Invalid())
assert.Equal(t, gitw.DefaultRemoteName, rt.Name)
assert.Equal(t, "[email protected]:gookit/gitw.git", rt.GitURL())
assert.Equal(t, "http://github.com/gookit/gitw", rt.URLOfHTTP())
assert.Equal(t, "https://github.com/gookit/gitw", rt.URLOfHTTPS())
assert.Eq(t, gitw.DefaultRemoteName, rt.Name)
assert.Eq(t, "[email protected]:gookit/gitw.git", rt.GitURL())
assert.Eq(t, "http://github.com/gookit/gitw", rt.URLOfHTTP())
assert.Eq(t, "https://github.com/gookit/gitw", rt.URLOfHTTPS())

rt = repo.RandomRemoteInfo(gitw.RemoteTypePush)
assert.NotEmpty(t, rt)
}

func TestRepo_AutoMatchTag(t *testing.T) {
assert.Equal(t, "HEAD", repo.AutoMatchTag("head"))
assert.Equal(t, "541fb9d", repo.AutoMatchTag("541fb9d"))
assert.Eq(t, "HEAD", repo.AutoMatchTag("head"))
assert.Eq(t, "541fb9d", repo.AutoMatchTag("541fb9d"))
}

func TestRepo_BranchInfos(t *testing.T) {
Expand All @@ -66,8 +66,8 @@ func TestRepo_BranchInfos(t *testing.T) {

mbr := repo.BranchInfo("main")
if mbr != nil {
assert.Equal(t, "main", mbr.Name)
assert.Equal(t, "main", mbr.Short)
assert.Eq(t, "main", mbr.Name)
assert.Eq(t, "main", mbr.Short)
}
}

Expand All @@ -77,12 +77,12 @@ func TestRepo_Info(t *testing.T) {

assert.Nil(t, repo.Err())
assert.NotNil(t, info)
assert.Equal(t, "gitw", info.Name)
assert.Eq(t, "gitw", info.Name)
}

func TestRepo_AutoMatchTagByTagType(t *testing.T) {
assert.Equal(t, "HEAD", repo.AutoMatchTagByType("head", 0))
assert.Equal(t, "541fb9d", repo.AutoMatchTagByType("541fb9d", 0))
assert.Eq(t, "HEAD", repo.AutoMatchTagByType("head", 0))
assert.Eq(t, "541fb9d", repo.AutoMatchTagByType("541fb9d", 0))
}

func TestRepo_TagsSortedByCreatorDate(t *testing.T) {
Expand Down

0 comments on commit 8eb2535

Please sign in to comment.