MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceAgentRecreateDevcontainer

Function TestWorkspaceAgentRecreateDevcontainer

coderd/workspaceagents_test.go:1746–1877  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1744}
1745
1746func TestWorkspaceAgentRecreateDevcontainer(t *testing.T) {
1747 t.Parallel()
1748
1749 t.Run("Mock", func(t *testing.T) {
1750 t.Parallel()
1751
1752 var (
1753 workspaceFolder = t.TempDir()
1754 configFile = filepath.Join(workspaceFolder, ".devcontainer", "devcontainer.json")
1755 devcontainerID = uuid.New()
1756
1757 // Create a container that would be associated with the devcontainer
1758 devContainer = codersdk.WorkspaceAgentContainer{
1759 ID: uuid.NewString(),
1760 CreatedAt: dbtime.Now(),
1761 FriendlyName: testutil.GetRandomName(t),
1762 Image: "busybox:latest",
1763 Labels: map[string]string{
1764 agentcontainers.DevcontainerLocalFolderLabel: workspaceFolder,
1765 agentcontainers.DevcontainerConfigFileLabel: configFile,
1766 },
1767 Running: true,
1768 Status: "running",
1769 }
1770
1771 devcontainer = codersdk.WorkspaceAgentDevcontainer{
1772 ID: devcontainerID,
1773 Name: "test-devcontainer",
1774 WorkspaceFolder: workspaceFolder,
1775 ConfigPath: configFile,
1776 Status: codersdk.WorkspaceAgentDevcontainerStatusRunning,
1777 Container: &devContainer,
1778 }
1779 )
1780
1781 for _, tc := range []struct {
1782 name string
1783 devcontainerID string
1784 devcontainers []codersdk.WorkspaceAgentDevcontainer
1785 containers []codersdk.WorkspaceAgentContainer
1786 expectRecreate bool
1787 expectErrorCode int
1788 }{
1789 {
1790 name: "Recreate",
1791 devcontainerID: devcontainerID.String(),
1792 devcontainers: []codersdk.WorkspaceAgentDevcontainer{devcontainer},
1793 containers: []codersdk.WorkspaceAgentContainer{devContainer},
1794 expectRecreate: true,
1795 },
1796 {
1797 name: "Devcontainer does not exist",
1798 devcontainerID: uuid.NewString(),
1799 devcontainers: nil,
1800 containers: []codersdk.WorkspaceAgentContainer{},
1801 expectErrorCode: http.StatusNotFound,
1802 },
1803 } {

Callers

nothing calls this directly

Calls 15

NowFunction · 0.92
GetRandomNameFunction · 0.92
ContextFunction · 0.92
NewMockContainerCLIFunction · 0.92
NewMockDevcontainerCLIFunction · 0.92
NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
WithContainerCLIFunction · 0.92
WithDevcontainerCLIFunction · 0.92
WithWatcherFunction · 0.92
NewNoopFunction · 0.92

Tested by

no test coverage detected