-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: filecollector into new package (#2174)
* refactor: filecollector into new package * Add test for symlinks * add test fix bug of GetContainerArchive * add test data
- Loading branch information
1 parent
4ca35d2
commit 5a80a04
Showing
6 changed files
with
160 additions
and
35 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
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 |
---|---|---|
@@ -1,4 +1,71 @@ | ||
package container | ||
|
||
import ( | ||
"archive/tar" | ||
"context" | ||
"io" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Type assert HostEnvironment implements ExecutionsEnvironment | ||
var _ ExecutionsEnvironment = &HostEnvironment{} | ||
|
||
func TestCopyDir(t *testing.T) { | ||
dir, err := os.MkdirTemp("", "test-host-env-*") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dir) | ||
ctx := context.Background() | ||
e := &HostEnvironment{ | ||
Path: filepath.Join(dir, "path"), | ||
TmpDir: filepath.Join(dir, "tmp"), | ||
ToolCache: filepath.Join(dir, "tool_cache"), | ||
ActPath: filepath.Join(dir, "act_path"), | ||
StdOut: os.Stdout, | ||
Workdir: path.Join("testdata", "scratch"), | ||
} | ||
_ = os.MkdirAll(e.Path, 0700) | ||
_ = os.MkdirAll(e.TmpDir, 0700) | ||
_ = os.MkdirAll(e.ToolCache, 0700) | ||
_ = os.MkdirAll(e.ActPath, 0700) | ||
err = e.CopyDir(e.Workdir, e.Path, true)(ctx) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestGetContainerArchive(t *testing.T) { | ||
dir, err := os.MkdirTemp("", "test-host-env-*") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dir) | ||
ctx := context.Background() | ||
e := &HostEnvironment{ | ||
Path: filepath.Join(dir, "path"), | ||
TmpDir: filepath.Join(dir, "tmp"), | ||
ToolCache: filepath.Join(dir, "tool_cache"), | ||
ActPath: filepath.Join(dir, "act_path"), | ||
StdOut: os.Stdout, | ||
Workdir: path.Join("testdata", "scratch"), | ||
} | ||
_ = os.MkdirAll(e.Path, 0700) | ||
_ = os.MkdirAll(e.TmpDir, 0700) | ||
_ = os.MkdirAll(e.ToolCache, 0700) | ||
_ = os.MkdirAll(e.ActPath, 0700) | ||
expectedContent := []byte("sdde/7sh") | ||
err = os.WriteFile(filepath.Join(e.Path, "action.yml"), expectedContent, 0600) | ||
assert.NoError(t, err) | ||
archive, err := e.GetContainerArchive(ctx, e.Path) | ||
assert.NoError(t, err) | ||
defer archive.Close() | ||
reader := tar.NewReader(archive) | ||
h, err := reader.Next() | ||
assert.NoError(t, err) | ||
assert.Equal(t, "action.yml", h.Name) | ||
content, err := io.ReadAll(reader) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedContent, content) | ||
_, err = reader.Next() | ||
assert.ErrorIs(t, err, io.EOF) | ||
} |
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 @@ | ||
testfile |
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