Skip to content

Commit

Permalink
Cleanup a few unused functions (#528)
Browse files Browse the repository at this point in the history
* fix test for replayer

* use os.TempDir
  • Loading branch information
pepin-stripe authored Oct 30, 2020
1 parent d53708d commit 5825c30
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
17 changes: 7 additions & 10 deletions pkg/playback/http_playback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ func TestSimpleRecordReplayServerSeparately(t *testing.T) {
remoteURL = ts.URL

// Spin up an instance of the HTTP playback server in record mode
var cassetteBuffer bytes.Buffer
addressString := defaultLocalAddress
webhookURL := defaultLocalWebhookAddress // not used in this test

httpRecorder := newRecordServer(remoteURL, webhookURL)
err := httpRecorder.insertCassette(&cassetteBuffer)
httpWrapper, err := NewServer(remoteURL, webhookURL, os.TempDir(), Record, "cassette.yaml")
check(t, err)

server := httpRecorder.initializeServer(addressString)
server := httpWrapper.InitializeServer(addressString)
serverReady := make(chan struct{})
go func() {
addr := server.Addr
Expand Down Expand Up @@ -140,19 +138,18 @@ func TestSimpleRecordReplayServerSeparately(t *testing.T) {
assert.Equal(t, mockResponse2.StatusCode, res2.StatusCode)

// Shutdown record server
resShutdown, err := http.Post("http://localhost:8080/playback/stop", "text/plain", nil)
resShutdown, err := http.Get("http://localhost:8080/playback/cassette/eject")
server.Shutdown(context.TODO())
assert.NoError(t, err)
defer resShutdown.Body.Close()

// --- Set up a replay server
httpReplayer := newReplayServer(webhookURL)
err = httpReplayer.readCassette(&cassetteBuffer)
httpWrapper, err = NewServer(remoteURL, webhookURL, os.TempDir(), Replay, "cassette.yaml")
check(t, err)
server = httpWrapper.InitializeServer(addressString)

replayServer := httpReplayer.initializeServer(addressString)
go func() {
if err := replayServer.ListenAndServe(); err != http.ErrServerClosed {
if err := server.ListenAndServe(); err != http.ErrServerClosed {
// unexpected error
log.Fatalf("ListenAndServe(): %v", err)
}
Expand All @@ -179,7 +176,7 @@ func TestSimpleRecordReplayServerSeparately(t *testing.T) {
assert.Equal(t, mockResponse2.Body, bodyBytes2)

// Shutdown replay server
replayServer.Shutdown(context.TODO())
server.Shutdown(context.TODO())
}

// Test the full server by switching between modes, loading and ejecting cassettes, and sending real stripe requests
Expand Down
17 changes: 0 additions & 17 deletions pkg/playback/http_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,3 @@ func (httpRecorder *recordServer) handler(w http.ResponseWriter, r *http.Request
httpRecorder.log.Fatal(err)
}
}

func (httpRecorder *recordServer) initializeServer(address string) *http.Server {
customMux := http.NewServeMux()
server := &http.Server{Addr: address, Handler: customMux}

// --- Recorder control handlers
customMux.HandleFunc("/playback/stop", func(w http.ResponseWriter, r *http.Request) {
httpRecorder.log.Info("Received /playback/stop. Stopping...")

httpRecorder.recorder.saveAndClose()
})

// --- Default handler that proxies request and returns response from the remote
customMux.HandleFunc("/", httpRecorder.handler)

return server
}
9 changes: 0 additions & 9 deletions pkg/playback/http_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,3 @@ func (httpReplayer *replayServer) readAnyPendingWebhookRecordingsFromCassette()

return webhookRequests, webhookResponses, nil
}

func (httpReplayer *replayServer) initializeServer(address string) *http.Server {
customMux := http.NewServeMux()
customMux.HandleFunc("/", httpReplayer.handler)

server := &http.Server{Addr: address, Handler: customMux}

return server
}

0 comments on commit 5825c30

Please sign in to comment.