Skip to content

Commit

Permalink
Merge pull request #70 from whywaita/fix/format-slash
Browse files Browse the repository at this point in the history
RepoURL return only one slash
  • Loading branch information
whywaita authored Jun 16, 2021
2 parents 42f36e5 + 1266ed7 commit 28f61d7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/datastore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"database/sql"
"errors"
"fmt"
"path"
"net/url"
"strings"
"time"

uuid "github.com/satori/go.uuid"
Expand Down Expand Up @@ -75,7 +76,14 @@ func (t *Target) RepoURL() string {
serverURL = t.GHEDomain.String
}

return path.Join(serverURL, t.Scope)
s := strings.Split(serverURL, "://")

var u url.URL
u.Scheme = s[0]
u.Host = s[1]
u.Path = t.Scope

return u.String()
}

// OwnerRepo return :owner and :repo
Expand Down
48 changes: 48 additions & 0 deletions pkg/datastore/interface_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package datastore_test

import (
"database/sql"
"strings"
"testing"

"github.com/whywaita/myshoes/pkg/datastore"
)

func TestTarget_RepoURL(t *testing.T) {
tests := []struct {
input datastore.Target
want string
err bool
}{
{
input: datastore.Target{
GHEDomain: sql.NullString{
Valid: false,
String: "",
},
Scope: "example/octocat",
},
want: "https://github.com/example/octocat",
err: false,
},
{
input: datastore.Target{
GHEDomain: sql.NullString{
Valid: true,
String: "https://github-enterprise.example.com",
},
Scope: "example",
},
want: "https://github-enterprise.example.com/example",
err: false,
},
}

for _, test := range tests {
got := test.input.RepoURL()

if !strings.EqualFold(got, test.want) {
t.Fatalf("want %s, but got %s", test.want, got)
}
}
}

0 comments on commit 28f61d7

Please sign in to comment.