Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
test(integration): add integration test for status
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed Sep 15, 2023
1 parent 94e1a95 commit e192634
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions integration/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package test

import (
"bytes"
"crypto/rand"
"encoding/json"
"io"
"net/http"
"net/url"
"testing"
"time"

"github.com/filecoin-project/motion/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -45,6 +48,38 @@ func TestRoundTripPutAndGet(t *testing.T) {
require.Equal(t, wantBlob, gotBlob)
}

func TestRoundTripPutAndStatus(t *testing.T) {
env := NewEnvironment(t)
// make an 8MB random file -- to trigger at least one car generation
dataReader := io.LimitReader(rand.Reader, 8*(1<<20))

var postBlobResp api.PostBlobResponse
{
postResp, err := http.Post(requireJoinUrlPath(t, env.MotionAPIEndpoint, "v0", "blob"), "application/octet-stream", dataReader)
require.NoError(t, err)
defer func() { require.NoError(t, postResp.Body.Close()) }()
require.EqualValues(t, http.StatusCreated, postResp.StatusCode)
require.NoError(t, json.NewDecoder(postResp.Body).Decode(&postBlobResp))
t.Log(postBlobResp)
require.NotEmpty(t, postBlobResp.ID)
}

// get the status, and continue to check until we verify a deal was at least proposed through boost
{
require.EventuallyWithT(t, func(c *assert.CollectT) {
getResp, err := http.Get(requireJoinUrlPath(t, env.MotionAPIEndpoint, "v0", "blob", postBlobResp.ID, "status"))
assert.NoError(c, err)
defer func() { assert.NoError(c, getResp.Body.Close()) }()
assert.EqualValues(c, http.StatusOK, getResp.StatusCode)
jsonResp := json.NewDecoder(getResp.Body)
var decoded api.GetStatusResponse
err = jsonResp.Decode(&decoded)
assert.NoError(c, err)
assert.Greater(c, len(decoded.Replicas), 0)
}, 2*time.Minute, 5*time.Second, "never initiated deal making")
}
}

func requireJoinUrlPath(t *testing.T, base string, elem ...string) string {
joined, err := url.JoinPath(base, elem...)
require.NoError(t, err)
Expand Down

0 comments on commit e192634

Please sign in to comment.