Skip to content
Prev Previous commit
Next Next commit
Verify if build option is set
  • Loading branch information
mtojek committed Jul 13, 2023
commit 6fd3da54ee8ac29d7f13826cda6337d4f609ef10
16 changes: 15 additions & 1 deletion cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ func TestCreateWithRichParameters(t *testing.T) {

template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

inv, root := clitest.New(t, "create", "my-workspace", "--template", template.Name, "--build-options")
const workspaceName = "my-workspace"
inv, root := clitest.New(t, "create", workspaceName, "--template", template.Name, "--build-options")
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t).Attach(inv)
Expand Down Expand Up @@ -344,6 +345,19 @@ func TestCreateWithRichParameters(t *testing.T) {
}
}
<-doneChan

// Verify if build option is set
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

workspace, err := client.WorkspaceByOwnerAndName(ctx, user.UserID.String(), workspaceName, codersdk.WorkspaceOptions{})
require.NoError(t, err)
actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID)
require.NoError(t, err)
require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{
Name: ephemeralParameterName,
Value: ephemeralParameterValue,
})
})
}

Expand Down
15 changes: 15 additions & 0 deletions cli/restart_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cli_test

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/pty/ptytest"
Expand Down Expand Up @@ -110,5 +112,18 @@ func TestRestart(t *testing.T) {
}
}
<-doneChan

// Verify if build option is set
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

workspace, err := client.WorkspaceByOwnerAndName(ctx, user.UserID.String(), workspace.Name, codersdk.WorkspaceOptions{})
require.NoError(t, err)
actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID)
require.NoError(t, err)
require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{
Name: ephemeralParameterName,
Value: ephemeralParameterValue,
})
})
}
17 changes: 17 additions & 0 deletions cli/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/pty/ptytest"
"github.com/coder/coder/testutil"
)

const (
Expand Down Expand Up @@ -81,5 +85,18 @@ func TestStart(t *testing.T) {
}
}
<-doneChan

// Verify if build option is set
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

workspace, err := client.WorkspaceByOwnerAndName(ctx, workspace.OwnerName, workspace.Name, codersdk.WorkspaceOptions{})
require.NoError(t, err)
actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID)
require.NoError(t, err)
require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{
Name: ephemeralParameterName,
Value: ephemeralParameterValue,
})
})
}
20 changes: 18 additions & 2 deletions cli/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/pty/ptytest"
"github.com/coder/coder/testutil"
)

func TestUpdate(t *testing.T) {
Expand Down Expand Up @@ -190,12 +191,14 @@ func TestUpdateWithRichParameters(t *testing.T) {
immutableParameterName + ": " + immutableParameterValue + "\n" +
secondParameterName + ": " + secondParameterValue)

inv, root := clitest.New(t, "create", "my-workspace", "--template", template.Name, "--rich-parameter-file", parameterFile.Name(), "-y")
const workspaceName = "my-workspace"

inv, root := clitest.New(t, "create", workspaceName, "--template", template.Name, "--rich-parameter-file", parameterFile.Name(), "-y")
clitest.SetupConfig(t, client, root)
err := inv.Run()
assert.NoError(t, err)

inv, root = clitest.New(t, "update", "my-workspace", "--build-options")
inv, root = clitest.New(t, "update", workspaceName, "--build-options")
clitest.SetupConfig(t, client, root)

doneChan := make(chan struct{})
Expand All @@ -219,6 +222,19 @@ func TestUpdateWithRichParameters(t *testing.T) {
}
}
<-doneChan

// Verify if build option is set
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

workspace, err := client.WorkspaceByOwnerAndName(ctx, user.UserID.String(), workspaceName, codersdk.WorkspaceOptions{})
require.NoError(t, err)
actualParameters, err := client.WorkspaceBuildParameters(ctx, workspace.LatestBuild.ID)
require.NoError(t, err)
require.Contains(t, actualParameters, codersdk.WorkspaceBuildParameter{
Name: ephemeralParameterName,
Value: ephemeralParameterValue,
})
})
}

Expand Down