Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Konboi committed Apr 26, 2024
1 parent 41ce76a commit 32098c7
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions e2e_tests/branch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package e2e_tests

import (
"testing"

"github.com/aviator-co/av/internal/git/gittest"
"github.com/stretchr/testify/require"
)

func TestBranch(t *testing.T) {
repo := gittest.NewTempRepo(t)
Chdir(t, repo.Dir())

// To start, we create a simple two-stack where each stack has a single commit.
// Our stack looks like:
// stack-1: main -> 1a -> 1b
// stack-2: \ -> 2a -> 2b

// Then create new branch stack-3 use by "av branch" command
// stack-1: main -> 1a -> 1b
// stack-2: \ -> 2a -> 2b
// stack-3: \

// Setup initial state
require.Equal(t, 0, Cmd(t, "git", "checkout", "-b", "stack-1").ExitCode)
gittest.CommitFile(t, repo, "my-file", []byte("1a\n"), gittest.WithMessage("Commit 1a"))
gittest.CommitFile(t, repo, "my-file", []byte("1a\n1b\n"), gittest.WithMessage("Commit 1b"))
RequireAv(t, "stack", "branch", "stack-2")
gittest.CommitFile(t, repo, "my-file", []byte("1a\n1b\n2a\n"), gittest.WithMessage("Commit 2a"))
gittest.CommitFile(
t,
repo,
"my-file",
[]byte("1a\n1b\n2a\n2b\n"),
gittest.WithMessage("Commit 2b"),
)

tree := Av(t, "stack", "tree")
require.Contains(t, tree.Stdout, "stack-1")
require.Contains(t, tree.Stdout, "stack-2")
require.NotContains(t, tree.Stdout, "stack-3")

out := Av(t, "branch", "stack-3", "stack-1")
require.Equal(t, "Created branch stack-3 from stack-1\n", out.Stdout)

tree = Av(t, "stack", "tree")
require.Contains(t, tree.Stdout, "stack-1")
require.Contains(t, tree.Stdout, "stack-2")
require.Contains(t, tree.Stdout, "stack-3")

}

0 comments on commit 32098c7

Please sign in to comment.