-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout_test.go
48 lines (36 loc) · 1.2 KB
/
checkout_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package git_test
import (
"testing"
git "github.com/purpleclay/gitz"
"github.com/purpleclay/gitz/gittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCheckout(t *testing.T) {
log := `(HEAD -> branch-checkout, origin/branch-checkout) pass tests
write tests for branch checkout
(main, origin/main) docs: update existing project README`
gittest.InitRepository(t, gittest.WithLog(log))
client, _ := git.NewClient()
out, err := client.Checkout("main")
require.NoError(t, err)
// Inspect the raw git output
assert.Contains(t, out, "Switched to branch 'main'")
assert.Equal(t, gittest.LastCommit(t).Message, "docs: update existing project README")
}
func TestCheckoutCreatesLocalBranch(t *testing.T) {
gittest.InitRepository(t)
client, _ := git.NewClient()
_, err := client.Checkout("testing")
require.NoError(t, err)
branches := gittest.Branches(t)
remoteBranches := gittest.RemoteBranches(t)
assert.Contains(t, branches, "testing")
assert.NotContains(t, remoteBranches, "testing")
}
func TestCheckoutQueryingBranchesError(t *testing.T) {
nonWorkingDirectory(t)
client, _ := git.NewClient()
_, err := client.Checkout("testing")
require.Error(t, err)
}