| 1 | package command |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/isacikgoz/gitbatch/internal/git" |
| 8 | "github.com/stretchr/testify/require" |
| 9 | ) |
| 10 | |
| 11 | func TestDiffFile(t *testing.T) { |
| 12 | th := git.InitTestRepositoryFromLocal(t) |
| 13 | defer th.CleanUp(t) |
| 14 | |
| 15 | f := &git.File{ |
| 16 | AbsPath: filepath.Join(th.RepoPath, ".gitignore"), |
| 17 | Name: ".gitignore", |
| 18 | } |
| 19 | |
| 20 | _, err := testFile(th.RepoPath, f.Name) |
| 21 | require.NoError(t, err) |
| 22 | |
| 23 | var tests = []struct { |
| 24 | input *git.File |
| 25 | expected string |
| 26 | }{ |
| 27 | {f, ""}, |
| 28 | } |
| 29 | for _, test := range tests { |
| 30 | output, err := DiffFile(test.input) |
| 31 | require.NoError(t, err) |
| 32 | require.Equal(t, test.expected, output) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestDiffWithGoGit(t *testing.T) { |
| 37 | th := git.InitTestRepositoryFromLocal(t) |
| 38 | defer th.CleanUp(t) |
| 39 | |
| 40 | headRef, err := th.Repository.Repo.Head() |
| 41 | require.NoError(t, err) |
| 42 | var tests = []struct { |
| 43 | inp1 *git.Repository |
| 44 | inp2 string |
| 45 | expected string |
| 46 | }{ |
| 47 | {th.Repository, headRef.Hash().String(), ""}, |
| 48 | } |
| 49 | for _, test := range tests { |
| 50 | output, err := diffWithGoGit(test.inp1, test.inp2) |
| 51 | require.NoError(t, err) |
| 52 | require.False(t, len(output) == len(test.expected)) |
| 53 | } |
| 54 | } |