Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(provisionersdk): change test to use bash script instead of binary echo #12759

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 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions provisionersdk/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"os/exec"
"runtime"
"strings"
Expand All @@ -23,17 +22,19 @@ import (
"github.com/coder/coder/v2/provisionersdk"
)

// bashEcho is a script that calls the local `echo` with the arguments. This is preferable to
// sending the real `echo` binary since macOS 14.4+ immediately sigkills `echo` if it is copied to
// another directory and run locally.
const bashEcho = `#!/usr/bin/env bash
echo $@`

func TestAgentScript(t *testing.T) {
t.Parallel()
t.Run("Run", func(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
echoPath, err := exec.LookPath("echo")
require.NoError(t, err)
content, err := os.ReadFile(echoPath)
require.NoError(t, err)
render.Status(r, http.StatusOK)
render.Data(rw, r, content)
render.Data(rw, r, []byte(bashEcho))
}))
defer srv.Close()
srvURL, err := url.Parse(srv.URL)
Expand All @@ -46,9 +47,6 @@ func TestAgentScript(t *testing.T) {
}
script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
// In certain distributions "echo" is a part of coreutils, and determines
// it's functionality based on the exec path name.
script = strings.ReplaceAll(script, "BINARY_NAME=coder", "BINARY_NAME=echo")
// This is intentionally ran in single quotes to mimic how a customer may
// embed our script. Our scripts should not include any single quotes.
// nolint:gosec
Expand Down