-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support to checkout github pr (#12)
* feat: support to checkout github pr * fix the auth issues * support to checkout branch * add more unit tests Co-authored-by: rick <[email protected]>
- Loading branch information
1 parent
53ddb16
commit 8052720
Showing
7 changed files
with
212 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bin/ | ||
dist/ | ||
.idea/ | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_prRef(t *testing.T) { | ||
type args struct { | ||
pr int | ||
kind string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantRef string | ||
}{{ | ||
name: "gitlab", | ||
args: args{ | ||
pr: 1, | ||
kind: "gitlab", | ||
}, | ||
wantRef: "refs/merge-requests/1/head:pr-1", | ||
}, { | ||
name: "unknown", | ||
args: args{ | ||
pr: 1, | ||
kind: "unknown", | ||
}, | ||
wantRef: "", | ||
}, { | ||
name: "github", | ||
args: args{ | ||
pr: 1, | ||
kind: "github", | ||
}, | ||
wantRef: "refs/pull/1/head:pr-1", | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.wantRef, prRef(tt.args.pr, tt.args.kind), "prRef(%v, %v)", tt.args.pr, tt.args.kind) | ||
}) | ||
} | ||
} | ||
|
||
func Test_detectGitKind(t *testing.T) { | ||
type args struct { | ||
gitURL string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantKind string | ||
}{{ | ||
name: "github", | ||
args: args{ | ||
gitURL: "https://github.com/linuxsuren/gogit", | ||
}, | ||
wantKind: "github", | ||
}, { | ||
name: "gitlab", | ||
args: args{ | ||
gitURL: "[email protected]:demo/test.git", | ||
}, | ||
wantKind: "gitlab", | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.wantKind, detectGitKind(tt.args.gitURL), "detectGitKind(%v)", tt.args.gitURL) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetAuth(t *testing.T) { | ||
opt := &checkoutOption{ | ||
sshPrivateKey: "/tmp", | ||
} | ||
auth, err := opt.getAuth("[email protected]") | ||
assert.Nil(t, auth) | ||
assert.NotNil(t, err) | ||
|
||
auth, err = opt.getAuth("fake.com") | ||
assert.Nil(t, auth) | ||
assert.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters