41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/Tencent/WeKnora/internal/sandbox"
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
)
|
|
|
|
func TestSandboxConnectionCheckConfigAllowsTemplateDiscoveryAfterConnection(t *testing.T) {
|
|
incoming := &types.TenantSandboxConfig{
|
|
SandboxType: "e2b",
|
|
E2B: &types.E2BSandboxConfig{APIKey: "key"},
|
|
}
|
|
|
|
got := sandboxConnectionCheckConfig(incoming)
|
|
|
|
require.Equal(t, "__connection_check__", got.E2B.TemplateID)
|
|
require.Empty(t, incoming.E2B.TemplateID, "the submitted form must not be mutated")
|
|
}
|
|
|
|
func TestSandboxCheckReasonDockerUnavailableIncludesHost(t *testing.T) {
|
|
msg := sandboxCheckReason(&sandbox.RemoteError{
|
|
Kind: sandbox.RemoteErrorKindUnavailable,
|
|
Provider: sandbox.SandboxTypeDocker,
|
|
Message: "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?",
|
|
})
|
|
require.Contains(t, msg, "unix:///var/run/docker.sock")
|
|
require.Contains(t, msg, "docker context")
|
|
}
|
|
|
|
func TestRunStatelessSandboxCheckRemovedWithLocalBackend(t *testing.T) {
|
|
incoming := &types.TenantSandboxConfig{SandboxType: "local"}
|
|
|
|
_, err := sandbox.ResolveEffectiveConfig(incoming, sandbox.DefaultConfig())
|
|
|
|
require.ErrorIs(t, err, sandbox.ErrUnsupportedSandboxType)
|
|
}
|