|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "io" |
5 | 6 | "net/http" |
6 | 7 | "net/http/httptest" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | "github.com/ipfs/boxo/examples/gateway/common" |
10 | 11 | "github.com/ipfs/boxo/gateway" |
11 | | - "github.com/ipld/go-ipld-prime/codec/dagjson" |
12 | | - "github.com/ipld/go-ipld-prime/node/basicnode" |
13 | 12 | "github.com/stretchr/testify/assert" |
14 | 13 | ) |
15 | 14 |
|
@@ -62,48 +61,35 @@ func TestFile(t *testing.T) { |
62 | 61 | assert.EqualValues(t, string(body), "hello world\n") |
63 | 62 | } |
64 | 63 |
|
65 | | -func TestDirectoryAsDAG(t *testing.T) { |
| 64 | +func TestDirectoryAsRawBlock(t *testing.T) { |
66 | 65 | ts, f, err := newTestServer() |
67 | 66 | assert.NoError(t, err) |
68 | 67 | defer f.Close() |
69 | 68 |
|
70 | | - res, err := http.Get(ts.URL + "/ipfs/" + BaseCID + "?format=dag-json") |
| 69 | + res, err := http.Get(ts.URL + "/ipfs/" + BaseCID + "?format=raw") |
71 | 70 | assert.NoError(t, err) |
72 | 71 | defer res.Body.Close() |
73 | 72 |
|
74 | | - contentType := res.Header.Get("Content-Type") |
75 | | - assert.EqualValues(t, contentType, "application/vnd.ipld.dag-json") |
76 | | - |
77 | | - // Parses the DAG-JSON response. |
78 | | - dag := basicnode.Prototype.Any.NewBuilder() |
79 | | - err = dagjson.Decode(dag, res.Body) |
80 | | - assert.NoError(t, err) |
81 | | - |
82 | | - // Checks for the links inside the logical model. |
83 | | - links, err := dag.Build().LookupByString("Links") |
84 | | - assert.NoError(t, err) |
85 | | - |
86 | | - // Checks if there are 2 links. |
87 | | - assert.EqualValues(t, links.Length(), 2) |
88 | | - |
89 | | - // Check if the first item is correct. |
90 | | - n, err := links.LookupByIndex(0) |
91 | | - assert.NoError(t, err) |
92 | | - assert.NotNil(t, n) |
| 73 | + assert.Equal(t, http.StatusOK, res.StatusCode) |
93 | 74 |
|
94 | | - nameNode, err := n.LookupByString("Name") |
95 | | - assert.NoError(t, err) |
96 | | - assert.NotNil(t, nameNode) |
97 | | - |
98 | | - name, err := nameNode.AsString() |
99 | | - assert.NoError(t, err) |
100 | | - assert.EqualValues(t, name, "eye.png") |
| 75 | + contentType := res.Header.Get("Content-Type") |
| 76 | + assert.Equal(t, "application/vnd.ipld.raw", contentType) |
101 | 77 |
|
102 | | - hashNode, err := n.LookupByString("Hash") |
| 78 | + body, err := io.ReadAll(res.Body) |
103 | 79 | assert.NoError(t, err) |
104 | | - assert.NotNil(t, hashNode) |
105 | 80 |
|
106 | | - hash, err := hashNode.AsLink() |
107 | | - assert.NoError(t, err) |
108 | | - assert.EqualValues(t, hash.String(), "bafybeigmlfksb374fdkxih4urny2yiyazyra2375y2e4a72b3jcrnthnau") |
| 81 | + // Raw bytes of the dag-pb directory block |
| 82 | + expected := []byte{ |
| 83 | + 0x12, 0x33, 0x0a, 0x24, 0x01, 0x70, 0x12, 0x20, 0xcc, 0x59, 0x55, 0x20, |
| 84 | + 0xef, 0xfc, 0x28, 0xd5, 0x74, 0x1f, 0x94, 0x8b, 0x71, 0xac, 0x23, 0x00, |
| 85 | + 0xce, 0x22, 0x0d, 0x6f, 0xfd, 0xc6, 0x89, 0xc0, 0x7f, 0x41, 0xda, 0x45, |
| 86 | + 0x16, 0xcc, 0xed, 0x05, 0x12, 0x07, 0x65, 0x79, 0x65, 0x2e, 0x70, 0x6e, |
| 87 | + 0x67, 0x18, 0xd0, 0xc8, 0x10, 0x12, 0x33, 0x0a, 0x24, 0x01, 0x55, 0x12, |
| 88 | + 0x20, 0xa9, 0x48, 0x90, 0x4f, 0x2f, 0x0f, 0x47, 0x9b, 0x8f, 0x81, 0x97, |
| 89 | + 0x69, 0x4b, 0x30, 0x18, 0x4b, 0x0d, 0x2e, 0xd1, 0xc1, 0xcd, 0x2a, 0x1e, |
| 90 | + 0xc0, 0xfb, 0x85, 0xd2, 0x99, 0xa1, 0x92, 0xa4, 0x47, 0x12, 0x09, 0x68, |
| 91 | + 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x74, 0x78, 0x74, 0x18, 0x0c, 0x0a, 0x02, |
| 92 | + 0x08, 0x01, |
| 93 | + } |
| 94 | + assert.True(t, bytes.Equal(body, expected), "raw block bytes should match") |
109 | 95 | } |
0 commit comments