From bd425ff023d5c6d24486f2691eb4d1e76ef44060 Mon Sep 17 00:00:00 2001 From: James Bowes Date: Sun, 12 Sep 2021 08:52:38 -0300 Subject: [PATCH] Add a test case for etag handling with github --- impl/github_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/impl/github_test.go b/impl/github_test.go index 979c0a7..9f62924 100644 --- a/impl/github_test.go +++ b/impl/github_test.go @@ -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) + } +}