-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from mdb/improve-tests
improve unit tests!
- Loading branch information
Showing
10 changed files
with
258 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
SOURCE=./... | ||
GOFMT_FILES?=$$(find . -type f -name '*.go') | ||
VERSION?=0.1.0 | ||
VERSION?=0.1.1 | ||
|
||
default: build | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dispatch | ||
|
||
import ( | ||
"github.com/cli/go-gh/pkg/auth" | ||
"github.com/cli/go-gh/pkg/config" | ||
) | ||
|
||
// Conf implements the cliapi tokenGetter interface. | ||
// In the context of gh-dispatch, its only purpose is to provide | ||
// a configuration to the GH HTTP client configuration that | ||
// enables the retrieval of an auth token in the same standard way | ||
// that gh itself retrieves the auth token. | ||
type Conf struct { | ||
*config.Config | ||
} | ||
|
||
// AuthToken implements the cliapi tokenGetter interface | ||
// by providing a method for retrieving the auth token. | ||
func (c *Conf) AuthToken(hostname string) (string, string) { | ||
return auth.TokenForHost(hostname) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dispatch | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cli/go-gh/pkg/auth" | ||
) | ||
|
||
// ghRepo satisfies the ghrepo interface. | ||
// In the context of gh-dispatch, it enables the reuse of | ||
// functions packaged in the upstream github.com/cli/cli | ||
// codebase for rendering GH Actions run output. | ||
// See github.com/cli/cli/v2/internal/ghrepo. | ||
type ghRepo struct { | ||
Name string | ||
Owner string | ||
} | ||
|
||
func (r ghRepo) RepoName() string { | ||
return r.Name | ||
} | ||
|
||
func (r ghRepo) RepoOwner() string { | ||
return r.Owner | ||
} | ||
|
||
func (r ghRepo) RepoHost() string { | ||
host, _ := auth.DefaultHost() | ||
|
||
return host | ||
} | ||
|
||
func (r ghRepo) RepoFullName() string { | ||
return fmt.Sprintf("%s/%s", r.RepoOwner(), r.RepoName()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dispatch | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGHRepo(t *testing.T) { | ||
ghRepo := &ghRepo{ | ||
Name: "REPO", | ||
Owner: "OWNER", | ||
} | ||
|
||
assert.Equal(t, "OWNER/REPO", ghRepo.RepoFullName()) | ||
assert.Equal(t, "OWNER", ghRepo.RepoOwner()) | ||
assert.Equal(t, "REPO", ghRepo.RepoName()) | ||
assert.Equal(t, "github.com", ghRepo.RepoHost()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.