Skip to content

Commit

Permalink
Allow multiple recorded form responses for the same endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ChimeraCoder committed Jun 4, 2016
1 parent edf5178 commit 873c098
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions twitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ func init() {
// if one filename is the prefix of another, the prefix will always match
// check if there is a more specific filename that matches this request

// create local variable to avoid closing over `filename`
sourceFilename := filename

r.ParseForm()
specific := filename + "?" + r.Form.Encode()
specific := sourceFilename + "?" + r.Form.Encode()
_, err := os.Stat(specific)
if err == nil {
filename = specific
sourceFilename = specific

} else {
if err != nil && !os.IsNotExist(err) {
Expand All @@ -76,7 +79,7 @@ func init() {
}
}

f, err := os.Open(filename)
f, err := os.Open(sourceFilename)
if err != nil {
// either the file does not exist
// or something is seriously wrong with the testing environment
Expand All @@ -85,7 +88,7 @@ func init() {
defer f.Close()

// TODO not a hack
if filename == "json/statuses/show.json?id=404409873170841600" {
if sourceFilename == "json/statuses/show.json?id=404409873170841600" {
bts, err := ioutil.ReadAll(f)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down

0 comments on commit 873c098

Please sign in to comment.