chore: refactor time.Duration -> int64 milliseconds for FE consumption (#1944)

* Changes all public-facing codersdk types to use a plain int64 (milliseconds) instead of time.Duration.
* Makes autostart_schedule a *string as it may not be present.
* Adds a utils/ptr package with some useful methods.
This commit is contained in:
Cian Johnston
2022-06-02 11:23:34 +01:00
committed by GitHub
parent 51c420c90a
commit dcf03d8ba3
24 changed files with 287 additions and 148 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/util/ptr"
"github.com/coder/coder/codersdk"
)
@ -34,7 +35,7 @@ func TestAutostart(t *testing.T) {
)
err := client.UpdateWorkspaceAutostart(ctx, workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
Schedule: sched,
Schedule: ptr.Ref(sched),
})
require.NoError(t, err)
@ -76,7 +77,7 @@ func TestAutostart(t *testing.T) {
// Ensure autostart schedule updated
updated, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err, "fetch updated workspace")
require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set")
require.Equal(t, sched, *updated.AutostartSchedule, "expected autostart schedule to be set")
// Disable schedule
cmd, root = clitest.New(t, "autostart", "disable", workspace.Name)
@ -90,7 +91,7 @@ func TestAutostart(t *testing.T) {
// Ensure autostart schedule updated
updated, err = client.Workspace(ctx, workspace.ID)
require.NoError(t, err, "fetch updated workspace")
require.Empty(t, updated.AutostartSchedule, "expected autostart schedule to not be set")
require.Nil(t, updated.AutostartSchedule, "expected autostart schedule to not be set")
})
t.Run("Enable_NotFound", func(t *testing.T) {
@ -155,6 +156,6 @@ func TestAutostart(t *testing.T) {
// Ensure nothing happened
updated, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err, "fetch updated workspace")
require.Equal(t, expectedSchedule, updated.AutostartSchedule, "expected default autostart schedule")
require.Equal(t, expectedSchedule, *updated.AutostartSchedule, "expected default autostart schedule")
})
}