github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/archive/issues_test.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package archive 18 19 import ( 20 "bytes" 21 "context" 22 "io/ioutil" 23 "os" 24 "path/filepath" 25 "strings" 26 "testing" 27 28 "github.com/containerd/containerd/archive/compression" 29 "github.com/containerd/containerd/pkg/testutil" 30 ) 31 32 // TestPrefixHeaderReadable tests that files that could be created with the 33 // version of this package that was built with <=go17 are still readable. 34 func TestPrefixHeaderReadable(t *testing.T) { 35 testutil.RequiresRoot(t) 36 37 // https://gist.github.com/stevvooe/e2a790ad4e97425896206c0816e1a882#file-out-go 38 var testFile = []byte("\x1f\x8b\x08\x08\x44\x21\x68\x59\x00\x03\x74\x2e\x74\x61\x72\x00\x4b\xcb\xcf\x67\xa0\x35\x30\x80\x00\x86\x06\x10\x47\x01\xc1\x37\x40\x00\x54\xb6\xb1\xa1\xa9\x99\x09\x48\x25\x1d\x40\x69\x71\x49\x62\x91\x02\xe5\x76\xa1\x79\x84\x21\x91\xd6\x80\x72\xaf\x8f\x82\x51\x30\x0a\x46\x36\x00\x00\xf0\x1c\x1e\x95\x00\x06\x00\x00") 39 40 tmpDir, err := ioutil.TempDir("", "prefix-test") 41 if err != nil { 42 t.Fatal(err) 43 } 44 defer os.RemoveAll(tmpDir) 45 46 r, err := compression.DecompressStream(bytes.NewReader(testFile)) 47 if err != nil { 48 t.Fatal(err) 49 } 50 defer r.Close() 51 _, err = Apply(context.Background(), tmpDir, r) 52 if err != nil { 53 t.Fatal(err) 54 } 55 56 baseName := "foo" 57 pth := strings.Repeat("a", 100-len(baseName)) + "/" + baseName 58 59 _, err = os.Lstat(filepath.Join(tmpDir, pth)) 60 if err != nil { 61 t.Fatal(err) 62 } 63 }