| 1 | package command |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/isacikgoz/gitbatch/internal/git" |
| 7 | "github.com/stretchr/testify/require" |
| 8 | ) |
| 9 | |
| 10 | func TestConfigWithGit(t *testing.T) { |
| 11 | th := git.InitTestRepositoryFromLocal(t) |
| 12 | defer th.CleanUp(t) |
| 13 | |
| 14 | testConfigopt := &ConfigOptions{ |
| 15 | Section: "remote.origin", |
| 16 | Option: "url", |
| 17 | Site: ConfigSiteLocal, |
| 18 | } |
| 19 | |
| 20 | var tests = []struct { |
| 21 | inp1 *git.Repository |
| 22 | inp2 *ConfigOptions |
| 23 | expected string |
| 24 | }{ |
| 25 | {th.Repository, testConfigopt, "https://gitlab.com/isacikgoz/test-data.git"}, |
| 26 | } |
| 27 | for _, test := range tests { |
| 28 | output, err := configWithGit(test.inp1, test.inp2) |
| 29 | require.NoError(t, err) |
| 30 | require.Equal(t, test.expected, output) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestConfigWithGoGit(t *testing.T) { |
| 35 | th := git.InitTestRepositoryFromLocal(t) |
| 36 | defer th.CleanUp(t) |
| 37 | |
| 38 | testConfigopt := &ConfigOptions{ |
| 39 | Section: "core", |
| 40 | Option: "bare", |
| 41 | Site: ConfigSiteLocal, |
| 42 | } |
| 43 | |
| 44 | var tests = []struct { |
| 45 | inp1 *git.Repository |
| 46 | inp2 *ConfigOptions |
| 47 | expected string |
| 48 | }{ |
| 49 | {th.Repository, testConfigopt, "false"}, |
| 50 | } |
| 51 | for _, test := range tests { |
| 52 | output, err := configWithGoGit(test.inp1, test.inp2) |
| 53 | require.NoError(t, err) |
| 54 | require.Equal(t, output, test.expected) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestAddConfigWithGit(t *testing.T) { |
| 59 | th := git.InitTestRepositoryFromLocal(t) |
| 60 | defer th.CleanUp(t) |
| 61 | |
| 62 | testConfigopt := &ConfigOptions{ |
| 63 | Section: "user", |
| 64 | Option: "name", |
| 65 | Site: ConfigSiteLocal, |
| 66 | } |
| 67 | |
| 68 | var tests = []struct { |
| 69 | inp1 *git.Repository |
| 70 | inp2 *ConfigOptions |
| 71 | inp3 string |
| 72 | }{ |
| 73 | {th.Repository, testConfigopt, "foo"}, |
| 74 | } |
| 75 | for _, test := range tests { |
| 76 | err := addConfigWithGit(test.inp1, test.inp2, test.inp3) |
| 77 | require.NoError(t, err) |
| 78 | } |
| 79 | } |