-
Notifications
You must be signed in to change notification settings - Fork 881
feat: add default autostart and ttl for new workspaces #1632
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5c092be
Dockerfile: add tzdata
johnstcn 391f527
database: add autostart_schedule and ttl to InsertWorkspace; make gen
johnstcn 98561bf
coderd: workspaces: consume additional fields of CreateWorkspaceRequest
johnstcn 0169315
fixup! coderd: workspaces: consume additional fields of CreateWorkspa…
johnstcn dea541f
fixup! fixup! coderd: workspaces: consume additional fields of Create…
johnstcn d621272
autobuild: fix unit tests
johnstcn 2f7b939
cli: update: add support for TTL and autostart_schedule
johnstcn 813a64f
cli: create: add unit tests
johnstcn 1fbc0f2
lint
johnstcn 142ad37
coder: use embedded tzdata instead
johnstcn 0f348cd
autobuild: fix unit test that only runs with a real db
johnstcn 32a86f1
address PR comments
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/cli/clitest" | ||
|
@@ -25,7 +26,17 @@ func TestCreate(t *testing.T) { | |
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) | ||
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) | ||
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) | ||
cmd, root := clitest.New(t, "create", "my-workspace", "--template", template.Name) | ||
args := []string{ | ||
"create", | ||
"my-workspace", | ||
"--template", template.Name, | ||
"--tz", "US/Central", | ||
"--autostart-minute", "0", | ||
"--autostart-hour", "*/2", | ||
"--autostart-day-of-week", "MON-FRI", | ||
"--ttl", "8h", | ||
} | ||
cmd, root := clitest.New(t, args...) | ||
clitest.SetupConfig(t, client, root) | ||
doneChan := make(chan struct{}) | ||
pty := ptytest.New(t) | ||
|
@@ -48,6 +59,60 @@ func TestCreate(t *testing.T) { | |
<-doneChan | ||
}) | ||
|
||
t.Run("CreateErrInvalidTz", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true}) | ||
user := coderdtest.CreateFirstUser(t, client) | ||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) | ||
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) | ||
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) | ||
args := []string{ | ||
"create", | ||
"my-workspace", | ||
"--template", template.Name, | ||
"--tz", "invalid", | ||
} | ||
cmd, root := clitest.New(t, args...) | ||
clitest.SetupConfig(t, client, root) | ||
doneChan := make(chan struct{}) | ||
pty := ptytest.New(t) | ||
cmd.SetIn(pty.Input()) | ||
cmd.SetOut(pty.Output()) | ||
go func() { | ||
defer close(doneChan) | ||
err := cmd.Execute() | ||
assert.EqualError(t, err, "Invalid workspace autostart timezone: unknown time zone invalid") | ||
}() | ||
<-doneChan | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we were hunting this style today, should we eliminate them here as well? 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these ones, I'm going to just use |
||
}) | ||
|
||
t.Run("CreateErrInvalidTTL", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true}) | ||
user := coderdtest.CreateFirstUser(t, client) | ||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) | ||
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) | ||
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) | ||
args := []string{ | ||
"create", | ||
"my-workspace", | ||
"--template", template.Name, | ||
"--ttl", "0s", | ||
} | ||
cmd, root := clitest.New(t, args...) | ||
clitest.SetupConfig(t, client, root) | ||
doneChan := make(chan struct{}) | ||
pty := ptytest.New(t) | ||
cmd.SetIn(pty.Input()) | ||
cmd.SetOut(pty.Output()) | ||
go func() { | ||
defer close(doneChan) | ||
err := cmd.Execute() | ||
assert.EqualError(t, err, "TTL must be at least 1 minute") | ||
}() | ||
<-doneChan | ||
}) | ||
|
||
t.Run("CreateFromListWithSkip", func(t *testing.T) { | ||
t.Parallel() | ||
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true}) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Error strings should not be capitalized: https://github.com/golang/go/wiki/CodeReviewComments#error-strings