diff --git a/ui/common/repopath_test.go b/ui/common/repopath_test.go index 352eeedb..06224e68 100644 --- a/ui/common/repopath_test.go +++ b/ui/common/repopath_test.go @@ -3,56 +3,54 @@ package common_test import ( "testing" - "github.com/dlvhdr/gh-dash/ui/common" -) + "github.com/stretchr/testify/require" -var ( - configPaths = map[string]string{ - "user/repo": "/path/to/user/repo", - "user_2/*": "/path/to/user_2/*", - } + "github.com/dlvhdr/gh-dash/ui/common" ) -func TestGetRepoLocalPathExactMatch(t *testing.T) { - want := "/path/to/user/repo" - got, found := common.GetRepoLocalPath("user/repo", configPaths) - if !found { - t.Errorf("expected to find path for repo 'user/repo'") - } - if want != got { - t.Errorf("want '%s', got '%s'", want, got) - } +var configPaths = map[string]string{ + "user/repo": "/path/to/user/repo", + "user_2/*": "/path/to/user_2/*", } -func TestGetRepoLocalPathExactNoMatch(t *testing.T) { - want := "" - got, found := common.GetRepoLocalPath("user/other_repo", configPaths) - if found { - t.Errorf("expected to not find path for repo 'user/other_repo'") - } - if want != got { - t.Errorf("want '%s', got '%s'", want, got) +func TestGetRepoLocalPath(t *testing.T) { + testCases := map[string]struct { + repo string + want string + found bool + configPaths map[string]string + }{ + "exact match": { + repo: "user/repo", + want: "/path/to/user/repo", + found: true, + configPaths: configPaths, + }, + "exact no match": { + repo: "user/other_repo", + want: "", + found: false, + configPaths: configPaths, + }, + "wildcard match": { + repo: "user_2/repo123", + want: "/path/to/user_2/repo123", + found: true, + configPaths: configPaths, + }, + "bad path": { + repo: "invalid-lookup", + want: "", + found: false, + configPaths: configPaths, + }, } -} - -func TestGetRepoLocalPathWildcardMatch(t *testing.T) { - want := "/path/to/user_2/repo123" - got, found := common.GetRepoLocalPath("user_2/repo123", configPaths) - if !found { - t.Errorf("expected to find path for repo 'user_2/repo123'") - } - if want != got { - t.Errorf("want '%s', got '%s'", want, got) - } -} -func TestGetRepoLocalPathBadPath(t *testing.T) { - want := "" - got, found := common.GetRepoLocalPath("invalid-lookup", configPaths) - if found { - t.Errorf("expected to not find path for repo 'invalid-lookup'") - } - if want != got { - t.Errorf("want '%s', got '%s'", want, got) + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + got, found := common.GetRepoLocalPath(tc.repo, tc.configPaths) + require.Equal(t, tc.want, got) + require.Equal(t, tc.found, found) + }) } }