| 1 | package command |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | giterr "github.com/isacikgoz/gitbatch/internal/errors" |
| 7 | "github.com/isacikgoz/gitbatch/internal/git" |
| 8 | "github.com/stretchr/testify/require" |
| 9 | ) |
| 10 | |
| 11 | func TestCommitWithGit(t *testing.T) { |
| 12 | th := git.InitTestRepositoryFromLocal(t) |
| 13 | defer th.CleanUp(t) |
| 14 | |
| 15 | f, err := testFile(th.RepoPath, "file") |
| 16 | require.NoError(t, err) |
| 17 | |
| 18 | err = addWithGit(th.Repository, f, testAddopt1) |
| 19 | require.NoError(t, err) |
| 20 | |
| 21 | testCommitopt1 := &CommitOptions{ |
| 22 | CommitMsg: "test", |
| 23 | User: "foo", |
| 24 | Email: "[email protected]", |
| 25 | } |
| 26 | |
| 27 | var tests = []struct { |
| 28 | inp1 *git.Repository |
| 29 | inp2 *CommitOptions |
| 30 | }{ |
| 31 | {th.Repository, testCommitopt1}, |
| 32 | } |
| 33 | for _, test := range tests { |
| 34 | err = commitWithGit(test.inp1, test.inp2) |
| 35 | require.False(t, err != nil && err == giterr.ErrUserEmailNotSet) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestCommitWithGoGit(t *testing.T) { |
| 40 | th := git.InitTestRepositoryFromLocal(t) |
| 41 | defer th.CleanUp(t) |
| 42 | |
| 43 | f, err := testFile(th.RepoPath, "file") |
| 44 | require.NoError(t, err) |
| 45 | |
| 46 | err = addWithGit(th.Repository, f, testAddopt1) |
| 47 | require.NoError(t, err) |
| 48 | |
| 49 | testCommitopt1 := &CommitOptions{ |
| 50 | CommitMsg: "test", |
| 51 | User: "foo", |
| 52 | Email: "[email protected]", |
| 53 | } |
| 54 | |
| 55 | var tests = []struct { |
| 56 | inp1 *git.Repository |
| 57 | inp2 *CommitOptions |
| 58 | }{ |
| 59 | {th.Repository, testCommitopt1}, |
| 60 | } |
| 61 | for _, test := range tests { |
| 62 | err = commitWithGoGit(test.inp1, test.inp2) |
| 63 | require.NoError(t, err) |
| 64 | } |
| 65 | } |