Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPFS e2e test #9

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions cmd/catalyst-uploader/catalyst-uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/uuid"
"github.com/livepeer/go-tools/drivers"
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -54,25 +55,35 @@ func testE2E(assert *assert.Assertions, fullUriStr string) {

// load object and compare contents
outUrl, _ := url.Parse(outJson.Uri)
fullUri, _ := outUrl.Parse(fullUriStr)
bucket := splitNonEmpty(fullUri.Path, '/')[0]
if !strings.Contains(outUrl.Host, bucket) {
// if bucket is not included in domain name of output URI, then it's already in the path
bucket = ""
if strings.Contains(fullUriStr, "ipfs://") {
cid := outUrl.Path
resp, err := http.Get("https://gateway.pinata.cloud/ipfs/" + cid)
assert.NoError(err)
defer resp.Body.Close()
ipfsData := new(bytes.Buffer)
ipfsData.ReadFrom(resp.Body)
assert.Equal(rndData, ipfsData.Bytes())
} else {
fullUri, _ := outUrl.Parse(fullUriStr)
bucket := splitNonEmpty(fullUri.Path, '/')[0]
if !strings.Contains(outUrl.Host, bucket) {
// if bucket is not included in domain name of output URI, then it's already in the path
bucket = ""
}
// compare key after leading slash
assert.Equal(fullUri.Path, path.Clean("/"+bucket+"/"+outUrl.Path))
os, err := drivers.ParseOSURL(fullUriStr, true)
assert.NoError(err)
session := os.NewSession("")
// second argument is object key and passed to API unmodified
data, err := session.ReadData(context.Background(), "")
assert.NoError(err)
assert.Equal(*data.Size, int64(len(rndData)))
osBuf := new(bytes.Buffer)
osBuf.ReadFrom(data.Body)
osData := osBuf.Bytes()
assert.Equal(rndData, osData)
}
// compare key after leading slash
assert.Equal(fullUri.Path, path.Clean("/"+bucket+"/"+outUrl.Path))
os, err := drivers.ParseOSURL(fullUriStr, true)
assert.NoError(err)
session := os.NewSession("")
// second argument is object key and passed to API unmodified
data, err := session.ReadData(context.Background(), "")
assert.NoError(err)
assert.Equal(*data.Size, int64(len(rndData)))
osBuf := new(bytes.Buffer)
osBuf.ReadFrom(data.Body)
osData := osBuf.Bytes()
assert.Equal(rndData, osData)
}

func TestFsHandlerE2E(t *testing.T) {
Expand Down Expand Up @@ -127,6 +138,18 @@ func TestS3HandlerE2E(t *testing.T) {
}
}

func TestIpfsHandlerE2E(t *testing.T) {
assert := assert.New(t)
key := os.Getenv("PINATA_KEY")
secret := os.Getenv("PINATA_SECRET")
if secret != "" {
uri := fmt.Sprintf("ipfs://%s:%s@%s/", key, secret, "pinata.cloud")
testE2E(assert, uri)
} else {
fmt.Println("No IPFS provider credentials, test skipped")
}
}

func TestMinioHandlerE2E(t *testing.T) {
assert := assert.New(t)
s3key := os.Getenv("MINIO_S3_KEY")
Expand Down