diff --git a/integration/test/integration_test.go b/integration/test/integration_test.go index 104c1a8..126a670 100644 --- a/integration/test/integration_test.go +++ b/integration/test/integration_test.go @@ -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" ) @@ -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)