Skip to content

Commit d50f437

Browse files
authored
Merge pull request #13 from jbowes/yet-more-tests
Add a test case for etag handling with github
2 parents fc29d68 + bd425ff commit d50f437

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

impl/github_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,37 @@ func TestGihubReleaser_errorOnBadJSON(t *testing.T) {
102102
t.Error("expected error but got none")
103103
}
104104
}
105+
106+
type etagTransport struct{}
107+
108+
func (etagTransport) RoundTrip(r *http.Request) (*http.Response, error) {
109+
if r.Header.Get("If-None-Match") != `"some-etag"` {
110+
return nil, errors.New("expected etag")
111+
}
112+
113+
resp := &http.Response{
114+
StatusCode: http.StatusNotModified,
115+
}
116+
return resp, nil
117+
}
118+
119+
func TestGihubReleaser_supportsEtag(t *testing.T) {
120+
ctx := context.Background()
121+
ghr := &impl.GitHubReleaser{
122+
URL: "http://github.com/repos/you/your-app/releases",
123+
Client: &http.Client{
124+
Transport: etagTransport{},
125+
},
126+
}
127+
etag := `"some-etag"`
128+
rels, outEtag, err := ghr.Get(ctx, etag)
129+
if err != nil {
130+
t.Error("unexpected error:", err)
131+
}
132+
if len(rels) != 0 {
133+
t.Error("expected no rels but got some")
134+
}
135+
if outEtag != etag {
136+
t.Error("incorrect etag. wanted:", etag, "got:", outEtag)
137+
}
138+
}

0 commit comments

Comments
 (0)