mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add support for external agents to API's and provisioner (#19286)
This pull request introduces support for external workspace management, allowing users to register and manage workspaces that are provisioned and managed outside of the Coder. Depends on: https://github.com/coder/terraform-provider-coder/pull/424 * GET /api/v2/init-script - Gets the agent initialization script * By default, it returns a script for Linux (amd64), but with query parameters (os and arch) you can get the init script for different platforms * GET /api/v2/workspaces/{workspace}/external-agent/{agent}/credentials - Gets credentials for an external agent **(enterprise)** * Updated queries to filter workspaces/templates by the has_external_agent field
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package coderd_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/coderdtest"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
func TestInitScript(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("OK Windows amd64", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
script, err := client.InitScript(context.Background(), "windows", "amd64")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, script)
|
||||
require.Contains(t, script, "$env:CODER_AGENT_AUTH = \"token\"")
|
||||
require.Contains(t, script, "/bin/coder-windows-amd64.exe")
|
||||
})
|
||||
|
||||
t.Run("OK Windows arm64", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
script, err := client.InitScript(context.Background(), "windows", "arm64")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, script)
|
||||
require.Contains(t, script, "$env:CODER_AGENT_AUTH = \"token\"")
|
||||
require.Contains(t, script, "/bin/coder-windows-arm64.exe")
|
||||
})
|
||||
|
||||
t.Run("OK Linux amd64", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
script, err := client.InitScript(context.Background(), "linux", "amd64")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, script)
|
||||
require.Contains(t, script, "export CODER_AGENT_AUTH=\"token\"")
|
||||
require.Contains(t, script, "/bin/coder-linux-amd64")
|
||||
})
|
||||
|
||||
t.Run("OK Linux arm64", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
script, err := client.InitScript(context.Background(), "linux", "arm64")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, script)
|
||||
require.Contains(t, script, "export CODER_AGENT_AUTH=\"token\"")
|
||||
require.Contains(t, script, "/bin/coder-linux-arm64")
|
||||
})
|
||||
|
||||
t.Run("BadRequest", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
_, err := client.InitScript(context.Background(), "darwin", "armv7")
|
||||
require.Error(t, err)
|
||||
var apiErr *codersdk.Error
|
||||
require.ErrorAs(t, err, &apiErr)
|
||||
require.Equal(t, http.StatusBadRequest, apiErr.StatusCode())
|
||||
require.Equal(t, "Unknown os/arch: darwin/armv7", apiErr.Message)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user