-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multi-test and complete t0123
- Loading branch information
1 parent
e616605
commit 8cd7e08
Showing
7 changed files
with
371 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Dataset description/sources | ||
|
||
- dag-cbor-traversal.car | ||
|
||
- dag-json-traversal.car | ||
|
||
- dag-pb.car | ||
|
||
- dag-pb.json | ||
|
||
- fixtures.car | ||
- raw CARv1 | ||
|
||
generated with: | ||
|
||
```sh | ||
# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) | ||
|
||
mkdir -p rootDir/ipfs && | ||
mkdir -p rootDir/ipns && | ||
mkdir -p rootDir/api && | ||
mkdir -p rootDir/ą/ę && | ||
echo "{ \"test\": \"i am a plain json file\" }" > rootDir/ą/ę/t.json && | ||
echo "I am a txt file on path with utf8" > rootDir/ą/ę/file-źł.txt && | ||
echo "I am a txt file in confusing /api dir" > rootDir/api/file.txt && | ||
echo "I am a txt file in confusing /ipfs dir" > rootDir/ipfs/file.txt && | ||
echo "I am a txt file in confusing /ipns dir" > rootDir/ipns/file.txt && | ||
DIR_CID=$(ipfs add -Qr --cid-version 1 rootDir) && | ||
FILE_JSON_CID=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/t.json | jq -r .Hash) && | ||
FILE_CID=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Hash) && | ||
FILE_SIZE=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Size) | ||
echo "$FILE_CID / $FILE_SIZE" | ||
|
||
echo DIR_CID=${DIR_CID} # ./rootDir | ||
echo FILE_JSON_CID=${FILE_JSON_CID} # ./rootDir/ą/ę/t.json | ||
echo FILE_CID=${FILE_CID} # ./rootDir/ą/ę/file-źł.txt | ||
echo FILE_SIZE=${FILE_SIZE} | ||
|
||
ipfs dag export ${DIR_CID} > fixtures.car | ||
|
||
DAG_CBOR_TRAVERSAL_CID="bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim" | ||
DAG_JSON_TRAVERSAL_CID="baguqeeram5ujjqrwheyaty3w5gdsmoz6vittchvhk723jjqxk7hakxkd47xq" | ||
DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke" | ||
|
||
test_native_dag() { | ||
NAME=$1 | ||
CID=$2 | ||
|
||
IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 ${NAME}_test_key | head -n1 | tr -d "\n") | ||
ipfs name publish --key ${NAME}_test_key --allow-offline --ttl=876600h --lifetime=876600h -Q "/ipfs/${CID}" > name_publish_out | ||
|
||
ipfs routing get /ipns/${IPNS_ID} > ${IPNS_ID}.ipns-record | ||
|
||
echo "IPNS_ID_${NAME}=${IPNS_ID}" | ||
} | ||
|
||
test_native_dag "DAG_JSON" "$DAG_JSON_TRAVERSAL_CID" | ||
test_native_dag "DAG_CBOR" "$DAG_CBOR_TRAVERSAL_CID" | ||
|
||
# DIR_CID=bafybeiafyvqlazbbbtjnn6how5d6h6l6rxbqc4qgpbmteaiskjrffmyy4a # ./rootDir | ||
# FILE_JSON_CID=bafkreibrppizs3g7axs2jdlnjua6vgpmltv7k72l7v7sa6mmht6mne3qqe # ./rootDir/ą/ę/t.json | ||
# FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt | ||
# FILE_SIZE=34 | ||
# IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2 | ||
# IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
type Reporter func(t *testing.T, msg interface{}, rest ...interface{}) | ||
|
||
func runRequest(ctx context.Context, t *testing.T, test SugarTest, builder RequestBuilder) (*http.Request, *http.Response, Reporter) { | ||
method := builder.Method_ | ||
if method == "" { | ||
method = "GET" | ||
} | ||
|
||
// Prepare a client, | ||
// use proxy, deal with redirects, etc. | ||
client := &http.Client{} | ||
if builder.UseProxyTunnel_ { | ||
if builder.Proxy_ == "" { | ||
t.Fatal("ProxyTunnel requires a proxy") | ||
} | ||
|
||
client = NewProxyTunnelClient(builder.Proxy_) | ||
} else if builder.Proxy_ != "" { | ||
client = NewProxyClient(builder.Proxy_) | ||
} | ||
|
||
if builder.DoNotFollowRedirects_ { | ||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error { | ||
return http.ErrUseLastResponse | ||
} | ||
} | ||
|
||
var res *http.Response = nil | ||
var req *http.Request = nil | ||
|
||
var localReport Reporter = func(t *testing.T, msg interface{}, rest ...interface{}) { | ||
var err error | ||
switch msg := msg.(type) { | ||
case string: | ||
err = fmt.Errorf(msg, rest...) | ||
case error: | ||
err = msg | ||
default: | ||
panic("msg must be string or error") | ||
} | ||
|
||
report(t, test, req, res, err) | ||
} | ||
|
||
var url string | ||
if builder.URL_ != "" && builder.Path_ != "" { | ||
localReport(t, "Both 'URL' and 'Path' are set") | ||
} | ||
if builder.URL_ == "" && builder.Path_ == "" { | ||
localReport(t, "Neither 'URL' nor 'Path' are set") | ||
} | ||
if builder.URL_ != "" { | ||
url = builder.URL_ | ||
} | ||
if builder.Path_ != "" { | ||
url = fmt.Sprintf("%s/%s", GatewayURL, builder.Path_) | ||
} | ||
|
||
query := builder.Query_.Encode() | ||
if query != "" { | ||
url = fmt.Sprintf("%s?%s", url, query) | ||
} | ||
|
||
var body io.Reader | ||
if builder.Body_ != nil { | ||
body = bytes.NewBuffer(builder.Body_) | ||
} | ||
|
||
// create a request | ||
req, err := http.NewRequest(method, url, body) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// add headers | ||
for key, value := range builder.Headers_ { | ||
req.Header.Add(key, value) | ||
|
||
// https://github.com/golang/go/issues/7682 | ||
if key == "Host" { | ||
req.Host = value | ||
} | ||
} | ||
|
||
// send request | ||
log.Debugf("Querying %s", url) | ||
req = req.WithContext(ctx) | ||
|
||
res, err = client.Do(req) | ||
if err != nil { | ||
localReport(t, "Querying %s failed: %s", url, err) | ||
} | ||
|
||
return req, res, localReport | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.