@@ -161,57 +161,93 @@ func TestReadOnlyStorage_DirFS(t *testing.T) {
161161 }
162162}
163163
164- func TestReadOnlyStorage_TarFS (t * testing.T ) {
165- s , err := NewStorageFromTar ("testdata/hello-world.tar" )
166- if err != nil {
167- t .Fatal ("NewStorageFromTar() error =" , err )
168- }
169- ctx := context .Background ()
170-
171- // test data in testdata/hello-world.tar
172- blob := []byte (`{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/hello"],"Image":"sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"8746661ca3c2f215da94e6d3f7dfdcafaff5ec0b21c9aff6af3dc379a82fbc72","container_config":{"Hostname":"8746661ca3c2","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","CMD [\"/hello\"]"],"Image":"sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"created":"2021-09-23T23:47:57.442225064Z","docker_version":"20.10.7","history":[{"created":"2021-09-23T23:47:57.098990892Z","created_by":"/bin/sh -c #(nop) COPY file:50563a97010fd7ce1ceebd1fa4f4891ac3decdf428333fb2683696f4358af6c2 in / "},{"created":"2021-09-23T23:47:57.442225064Z","created_by":"/bin/sh -c #(nop) CMD [\"/hello\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359"]}}` )
173- desc := content .NewDescriptorFromBytes (docker .MediaTypeManifest , blob )
174-
175- // test Exists
176- exists , err := s .Exists (ctx , desc )
177- if err != nil {
178- t .Fatal ("ReadOnlyStorage.Exists() error =" , err )
179- }
180- if want := true ; exists != want {
181- t .Errorf ("ReadOnlyStorage.Exists() = %v, want %v" , exists , want )
182- }
183-
184- // test Fetch
185- rc , err := s .Fetch (ctx , desc )
186- if err != nil {
187- t .Fatal ("ReadOnlyStorage.Fetch() error =" , err )
188- }
189- got , err := io .ReadAll (rc )
190- if err != nil {
191- t .Fatal ("ReadOnlyStorage.Fetch().Read() error =" , err )
192- }
193- err = rc .Close ()
194- if err != nil {
195- t .Error ("ReadOnlyStorage.Fetch().Close() error =" , err )
196- }
197- if ! bytes .Equal (got , blob ) {
198- t .Errorf ("ReadOnlyStorage.Fetch() = %v, want %v" , got , blob )
199- }
164+ /*
165+ === Contents of testdata/hello-world.tar ===
166+
167+ blobs/
168+ blobs/sha256/
169+ blobs/sha256/2db29710123e3e53a794f2694094b9b4338aa9ee5c40b930cb8063a1be392c54
170+ blobs/sha256/f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4
171+ blobs/sha256/faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
172+ blobs/sha256/feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
173+ index.json
174+ manifest.json
175+ oci-layout
176+
177+ === Contents of testdata/hello-world-prefixed-path.tar ===
178+
179+ ./
180+ ./blobs/
181+ ./blobs/sha256/
182+ ./blobs/sha256/2db29710123e3e53a794f2694094b9b4338aa9ee5c40b930cb8063a1be392c54
183+ ./blobs/sha256/f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4
184+ ./blobs/sha256/faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
185+ ./blobs/sha256/feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
186+ ./index.json
187+ ./manifest.json
188+ ./oci-layout
200189
201- // test Exists against a non-existing content
202- blob = []byte ("whatever" )
203- desc = content .NewDescriptorFromBytes ("" , blob )
204- exists , err = s .Exists (ctx , desc )
205- if err != nil {
206- t .Fatal ("ReadOnlyStorage.Exists() error =" , err )
207- }
208- if want := false ; exists != want {
209- t .Errorf ("ReadOnlyStorage.Exists() = %v, want %v" , exists , want )
210- }
190+ */
211191
212- // test Fetch against a non-existing content
213- _ , err = s .Fetch (ctx , desc )
214- if want := errdef .ErrNotFound ; ! errors .Is (err , want ) {
215- t .Errorf ("ReadOnlyStorage.Fetch() error = %v, wantErr %v" , err , want )
192+ func TestReadOnlyStorage_TarFS (t * testing.T ) {
193+ tarPaths := []string {
194+ "testdata/hello-world.tar" ,
195+ "testdata/hello-world-prefixed-path.tar" ,
196+ }
197+ for _ , tarPath := range tarPaths {
198+ t .Run (tarPath , func (t * testing.T ) {
199+ s , err := NewStorageFromTar (tarPath )
200+ if err != nil {
201+ t .Fatal ("NewStorageFromTar() error =" , err )
202+ }
203+ ctx := context .Background ()
204+
205+ // test data in testdata/hello-world.tar and testdata/hello-world-prefixed-path.tar
206+ blob := []byte (`{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/hello"],"Image":"sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"8746661ca3c2f215da94e6d3f7dfdcafaff5ec0b21c9aff6af3dc379a82fbc72","container_config":{"Hostname":"8746661ca3c2","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","CMD [\"/hello\"]"],"Image":"sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"created":"2021-09-23T23:47:57.442225064Z","docker_version":"20.10.7","history":[{"created":"2021-09-23T23:47:57.098990892Z","created_by":"/bin/sh -c #(nop) COPY file:50563a97010fd7ce1ceebd1fa4f4891ac3decdf428333fb2683696f4358af6c2 in / "},{"created":"2021-09-23T23:47:57.442225064Z","created_by":"/bin/sh -c #(nop) CMD [\"/hello\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359"]}}` )
207+ desc := content .NewDescriptorFromBytes (docker .MediaTypeManifest , blob )
208+
209+ // test Exists
210+ exists , err := s .Exists (ctx , desc )
211+ if err != nil {
212+ t .Fatal ("ReadOnlyStorage.Exists() error =" , err )
213+ }
214+ if want := true ; exists != want {
215+ t .Errorf ("ReadOnlyStorage.Exists() = %v, want %v" , exists , want )
216+ }
217+
218+ // test Fetch
219+ rc , err := s .Fetch (ctx , desc )
220+ if err != nil {
221+ t .Fatal ("ReadOnlyStorage.Fetch() error =" , err )
222+ }
223+ got , err := io .ReadAll (rc )
224+ if err != nil {
225+ t .Fatal ("ReadOnlyStorage.Fetch().Read() error =" , err )
226+ }
227+ err = rc .Close ()
228+ if err != nil {
229+ t .Error ("ReadOnlyStorage.Fetch().Close() error =" , err )
230+ }
231+ if ! bytes .Equal (got , blob ) {
232+ t .Errorf ("ReadOnlyStorage.Fetch() = %v, want %v" , got , blob )
233+ }
234+
235+ // test Exists against a non-existing content
236+ blob = []byte ("whatever" )
237+ desc = content .NewDescriptorFromBytes ("" , blob )
238+ exists , err = s .Exists (ctx , desc )
239+ if err != nil {
240+ t .Fatal ("ReadOnlyStorage.Exists() error =" , err )
241+ }
242+ if want := false ; exists != want {
243+ t .Errorf ("ReadOnlyStorage.Exists() = %v, want %v" , exists , want )
244+ }
245+
246+ // test Fetch against a non-existing content
247+ _ , err = s .Fetch (ctx , desc )
248+ if want := errdef .ErrNotFound ; ! errors .Is (err , want ) {
249+ t .Errorf ("ReadOnlyStorage.Fetch() error = %v, wantErr %v" , err , want )
250+ }
251+ })
216252 }
217253}
0 commit comments