Skip to content

Commit

Permalink
Merge pull request #13 from jbowes/yet-more-tests
Browse files Browse the repository at this point in the history
Add a test case for etag handling with github
  • Loading branch information
jbowes authored Sep 12, 2021
2 parents fc29d68 + bd425ff commit d50f437
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions impl/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,37 @@ func TestGihubReleaser_errorOnBadJSON(t *testing.T) {
t.Error("expected error but got none")
}
}

type etagTransport struct{}

func (etagTransport) RoundTrip(r *http.Request) (*http.Response, error) {
if r.Header.Get("If-None-Match") != `"some-etag"` {
return nil, errors.New("expected etag")
}

resp := &http.Response{
StatusCode: http.StatusNotModified,
}
return resp, nil
}

func TestGihubReleaser_supportsEtag(t *testing.T) {
ctx := context.Background()
ghr := &impl.GitHubReleaser{
URL: "http://github.com/repos/you/your-app/releases",
Client: &http.Client{
Transport: etagTransport{},
},
}
etag := `"some-etag"`
rels, outEtag, err := ghr.Get(ctx, etag)
if err != nil {
t.Error("unexpected error:", err)
}
if len(rels) != 0 {
t.Error("expected no rels but got some")
}
if outEtag != etag {
t.Error("incorrect etag. wanted:", etag, "got:", outEtag)
}
}

0 comments on commit d50f437

Please sign in to comment.