|
| 1 | +package gitutil |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/lighttiger2505/lab/git" |
| 8 | + "github.com/lighttiger2505/lab/internal/config" |
| 9 | +) |
| 10 | + |
| 11 | +func Test_filterHasGitlabDomain(t *testing.T) { |
| 12 | + |
| 13 | + gitlabRemoteInfo := &git.RemoteInfo{ |
| 14 | + |
| 15 | + Domain: "gitlab.com", |
| 16 | + } |
| 17 | + githubRemoteInfo := &git.RemoteInfo{ |
| 18 | + |
| 19 | + Domain: "github.com", |
| 20 | + } |
| 21 | + type args struct { |
| 22 | + remoteInfos []*git.RemoteInfo |
| 23 | + cfg *config.Config |
| 24 | + } |
| 25 | + tests := []struct { |
| 26 | + name string |
| 27 | + args args |
| 28 | + want []*git.RemoteInfo |
| 29 | + }{ |
| 30 | + { |
| 31 | + name: "find the gitlab domain", |
| 32 | + args: args{ |
| 33 | + remoteInfos: []*git.RemoteInfo{ |
| 34 | + gitlabRemoteInfo, |
| 35 | + githubRemoteInfo, |
| 36 | + }, |
| 37 | + cfg: &config.Config{ |
| 38 | + Profiles: map[string]config.Profile{}, |
| 39 | + }, |
| 40 | + }, |
| 41 | + want: []*git.RemoteInfo{gitlabRemoteInfo}, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "find the gitlab domain specified in the config file", |
| 45 | + args: args{ |
| 46 | + remoteInfos: []*git.RemoteInfo{ |
| 47 | + gitlabRemoteInfo, |
| 48 | + githubRemoteInfo, |
| 49 | + }, |
| 50 | + cfg: &config.Config{ |
| 51 | + Profiles: map[string]config.Profile{ |
| 52 | + "gitlab.com": {}, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + want: []*git.RemoteInfo{gitlabRemoteInfo}, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "find the other domain specified in the config file", |
| 60 | + args: args{ |
| 61 | + remoteInfos: []*git.RemoteInfo{ |
| 62 | + gitlabRemoteInfo, |
| 63 | + githubRemoteInfo, |
| 64 | + }, |
| 65 | + cfg: &config.Config{ |
| 66 | + Profiles: map[string]config.Profile{ |
| 67 | + "gitlab.com": {}, |
| 68 | + "github.com": {}, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + want: []*git.RemoteInfo{gitlabRemoteInfo, githubRemoteInfo}, |
| 73 | + }, |
| 74 | + { |
| 75 | + name: "not found", |
| 76 | + args: args{ |
| 77 | + remoteInfos: []*git.RemoteInfo{ |
| 78 | + githubRemoteInfo, |
| 79 | + }, |
| 80 | + cfg: &config.Config{ |
| 81 | + Profiles: map[string]config.Profile{ |
| 82 | + "gitlab.com": {}, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + want: []*git.RemoteInfo{}, |
| 87 | + }, |
| 88 | + } |
| 89 | + for _, tt := range tests { |
| 90 | + t.Run(tt.name, func(t *testing.T) { |
| 91 | + if got := filterHasGitlabDomain(tt.args.remoteInfos, tt.args.cfg); !reflect.DeepEqual(got, tt.want) { |
| 92 | + t.Errorf("filterHasGitlabDomain() = %v, want %v", got, tt.want) |
| 93 | + } |
| 94 | + }) |
| 95 | + } |
| 96 | +} |
0 commit comments