Skip to content

Commit

Permalink
Use httptest server.
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Sep 30, 2021
1 parent 724a5b6 commit 3b9a57d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions provider/bidengine/pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"math/big"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -551,24 +552,21 @@ func Test_ScriptPricingWritesJsonToStdin(t *testing.T) {
func Test_ScriptPricingFromScript(t *testing.T) {
const (
mockAPIResponse = `{"akash-network":{"usd":3.57}}`
addr = "localhost:8080"
expectedPrice = 67843138
)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprint(w, mockAPIResponse)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(mockAPIResponse))
require.NoError(t, err)
})
}))
defer server.Close()

go func() {
t.Error(http.ListenAndServe(addr, nil))
}()

err := os.Setenv("API_URL", addr)
err := os.Setenv("API_URL", server.URL)
require.NoError(t, err)

scriptPath, err := filepath.Abs("../../script/usd_pricing_oracle.sh")
require.NoError(t, err)

pricing, err := MakeShellScriptPricing(scriptPath, 1, 30000*time.Millisecond)
require.NoError(t, err)
require.NotNil(t, pricing)
Expand Down

0 comments on commit 3b9a57d

Please sign in to comment.