Skip to content

Commit

Permalink
use os agnostic paths for repospec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jul 7, 2021
1 parent 0c5f648 commit 1b45739
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package git
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
Expand All @@ -19,7 +20,7 @@ import (
// in various outputs (especially tests). Not using an
// actual directory name here, as that's a temporary directory
// with a unique name that isn't created until clone time.
const notCloned = filesys.ConfirmedDir("/notCloned")
const notCloned = filesys.ConfirmedDir(string(os.PathSeparator) + "notCloned")

// RepoSpec specifies a git repository and a branch and path therein.
type RepoSpec struct {
Expand Down
10 changes: 9 additions & 1 deletion api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package git

import (
"fmt"
"os"
"path"
"strings"
"testing"
Expand Down Expand Up @@ -90,13 +91,20 @@ func TestNewRepoSpecFromUrl(t *testing.T) {
}

var badData = [][]string{
{"/tmp", "uri looks like abs path"},
{absPrefix() + "tmp", "uri looks like abs path"},
{"iauhsdiuashduas", "url lacks orgRepo"},
{"htxxxtp://github.com/", "url lacks host"},
{"ssh://git.example.com", "url lacks orgRepo"},
{"git::___", "url lacks orgRepo"},
}

func absPrefix() string {
if os.PathSeparator == '\\' {
return "C:\\"
}
return string(os.PathSeparator)
}

func TestNewRepoSpecFromUrlErrors(t *testing.T) {
for _, tuple := range badData {
_, err := NewRepoSpecFromUrl(tuple[0])
Expand Down

0 comments on commit 1b45739

Please sign in to comment.