1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
12
"github.com/stretchr/testify/suite"
15
type CommonSuite struct {
21
var filesFixture = []struct {
28
Path: "/etc/hostname",
30
Contents: []byte("localhost"),
33
Path: "/etc/certs/ca.crt",
35
Contents: []byte("-- CA PEM CERT -- VERY SECRET"),
39
Mode: 0o600 | os.ModeDevice | os.ModeCharDevice,
44
Contents: []byte("ELF EXECUTABLE IIRC"),
48
Mode: 0o644 | os.ModeSymlink,
49
Contents: []byte("/usr/bin/cp"),
52
Path: "/lib/dynalib.so",
54
Contents: []byte("SOME LIBRARY OUT THERE"),
59
func (suite *CommonSuite) SetupSuite() {
60
suite.tmpDir = suite.T().TempDir()
62
for _, file := range filesFixture {
63
suite.Require().NoError(os.MkdirAll(filepath.Join(suite.tmpDir, filepath.Dir(file.Path)), 0o777))
65
if file.Mode&os.ModeSymlink != 0 {
66
suite.Require().NoError(os.Symlink(string(file.Contents), filepath.Join(suite.tmpDir, file.Path)))
71
f, err := os.OpenFile(filepath.Join(suite.tmpDir, file.Path), os.O_CREATE|os.O_WRONLY, file.Mode)
72
suite.Require().NoError(err)
77
contents = bytes.Repeat(file.Contents, file.Size/len(file.Contents))
78
contents = append(contents, file.Contents[:file.Size-file.Size/len(file.Contents)*len(file.Contents)]...)
80
contents = file.Contents
83
_, err = f.Write(contents)
84
suite.Require().NoError(err)
86
suite.Require().NoError(f.Close())