Skip to content

Commit

Permalink
refactor: update repopath to use table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markfeinstein authored and dlvhdr committed Feb 7, 2024
1 parent 466c7cd commit f76c49e
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions ui/common/repopath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit f76c49e

Please sign in to comment.