8000 feat(agent): add script data dir for binaries and files by mafredri · Pull Request #12205 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat(agent): add script data dir for binaries and files #12205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 20, 2024
Prev Previous commit
Next Next commit
add agentscript test
  • Loading branch information
mafredri committed Feb 19, 2024
commit 61007e8bf9cfc0eabd43cbdb41b5671e29891389
33 changes: 30 additions & 3 deletions agent/agentscripts/agentscripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package agentscripts_test

import (
"context"
"path/filepath"
"testing"
"time"

"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
Expand All @@ -30,7 +32,8 @@ func TestExecuteBasic(t *testing.T) {
})
defer runner.Close()
err := runner.Init([]codersdk.WorkspaceAgentScript{{
Script: "echo hello",
LogSourceID: uuid.New(),
Script: "echo hello",
}})
require.NoError(t, err)
require.NoError(t, runner.Execute(context.Background(), func(script codersdk.WorkspaceAgentScript) bool {
Expand All @@ -40,13 +43,36 @@ func TestExecuteBasic(t *testing.T) {
require.Equal(t, "hello", log.Logs[0].Output)
}

func TestEnv(t *testing.T) {
t.Parallel()
logs := make(chan agentsdk.PatchLogs, 1)
runner := setup(t, func(ctx context.Context, req agentsdk.PatchLogs) error {
logs <- req
return nil
})
9EA0 defer runner.Close()
id := uuid.New()
err := runner.Init([]codersdk.WorkspaceAgentScript{{
LogSourceID: id,
Script: "echo $CODER_SCRIPT_DATA_DIR\necho $CODER_SCRIPT_BIN_DIR\n",
}})
require.NoError(t, err)
require.NoError(t, runner.Execute(context.Background(), func(script codersdk.WorkspaceAgentScript) bool {
return true
}))
log := <-logs
require.Contains(t, log.Logs[0].Output, filepath.Join(runner.DataDir, "coder-script-data", id.String()))
require.Contains(t, log.Logs[1].Output, runner.ScriptBinDir())
}

func TestTimeout(t *testing.T) {
t.Parallel()
runner := setup(t, nil)
defer runner.Close()
err := runner.Init([]codersdk.WorkspaceAgentScript{{
Script: "sleep infinity",
Timeout: time.Millisecond,
LogSourceID: uuid.New(),
Script: "sleep infinity",
Timeout: time.Millisecond,
}})
require.NoError(t, err)
require.ErrorIs(t, runner.Execute(context.Background(), nil), agentscripts.ErrTimeout)
Expand Down Expand Up @@ -78,6 +104,7 @@ func setup(t *testing.T, patchLogs func(ctx context.Context, req agentsdk.PatchL
})
return agentscripts.New(agentscripts.Options{
LogDir: t.TempDir(),
DataDir: t.TempDir(),
Logger: logger,
SSHServer: s,
Filesystem: fs,
Expand Down
0