summaryrefslogtreecommitdiffstats
path: root/pkg/runner/step_run_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-20 23:07:42 +0200
committerDaniel Baumann <daniel@debian.org>2024-11-09 15:38:42 +0100
commit714c83b2736d7e308bc33c49057952490eb98be2 (patch)
tree1d9ba7035798368569cd49056f4d596efc908cd8 /pkg/runner/step_run_test.go
parentInitial commit. (diff)
downloadforgejo-act-714c83b2736d7e308bc33c49057952490eb98be2.tar.xz
forgejo-act-714c83b2736d7e308bc33c49057952490eb98be2.zip
Adding upstream version 1.21.4.HEADupstream/1.21.4upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'pkg/runner/step_run_test.go')
-rw-r--r--pkg/runner/step_run_test.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/pkg/runner/step_run_test.go b/pkg/runner/step_run_test.go
new file mode 100644
index 0000000..fc5e659
--- /dev/null
+++ b/pkg/runner/step_run_test.go
@@ -0,0 +1,94 @@
+package runner
+
+import (
+ "bytes"
+ "context"
+ "io"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
+
+ "github.com/nektos/act/pkg/container"
+ "github.com/nektos/act/pkg/model"
+)
+
+func TestStepRun(t *testing.T) {
+ cm := &containerMock{}
+ fileEntry := &container.FileEntry{
+ Name: "workflow/1.sh",
+ Mode: 0o755,
+ Body: "\ncmd\n",
+ }
+
+ sr := &stepRun{
+ RunContext: &RunContext{
+ StepResults: map[string]*model.StepResult{},
+ ExprEval: &expressionEvaluator{},
+ Config: &Config{},
+ Run: &model.Run{
+ JobID: "1",
+ Workflow: &model.Workflow{
+ Jobs: map[string]*model.Job{
+ "1": {
+ Defaults: model.Defaults{
+ Run: model.RunDefaults{
+ Shell: "bash",
+ },
+ },
+ },
+ },
+ },
+ },
+ JobContainer: cm,
+ },
+ Step: &model.Step{
+ ID: "1",
+ Run: "cmd",
+ WorkingDirectory: "workdir",
+ },
+ }
+
+ cm.On("Copy", "/var/run/act", []*container.FileEntry{fileEntry}).Return(func(ctx context.Context) error {
+ return nil
+ })
+ cm.On("Exec", []string{"bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "/var/run/act/workflow/1.sh"}, mock.AnythingOfType("map[string]string"), "", "workdir").Return(func(ctx context.Context) error {
+ return nil
+ })
+
+ cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(func(ctx context.Context) error {
+ return nil
+ })
+
+ cm.On("UpdateFromEnv", "/var/run/act/workflow/envs.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
+ return nil
+ })
+
+ cm.On("UpdateFromEnv", "/var/run/act/workflow/statecmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
+ return nil
+ })
+
+ cm.On("UpdateFromEnv", "/var/run/act/workflow/outputcmd.txt", mock.AnythingOfType("*map[string]string")).Return(func(ctx context.Context) error {
+ return nil
+ })
+
+ ctx := context.Background()
+
+ cm.On("GetContainerArchive", ctx, "/var/run/act/workflow/pathcmd.txt").Return(io.NopCloser(&bytes.Buffer{}), nil)
+
+ err := sr.main()(ctx)
+ assert.Nil(t, err)
+
+ cm.AssertExpectations(t)
+}
+
+func TestStepRunPrePost(t *testing.T) {
+ ctx := context.Background()
+ sr := &stepRun{}
+
+ err := sr.pre()(ctx)
+ assert.Nil(t, err)
+
+ err = sr.post()(ctx)
+ assert.Nil(t, err)
+}