Skip to content

Commit

Permalink
test: workspace configs
Browse files Browse the repository at this point in the history
  • Loading branch information
fracasula committed Dec 5, 2024
1 parent 0223eed commit aaac34a
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions modelv2/workspaceconfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/stretchr/testify/assert"
)

func TestWorkspaceConfigsUpdatedAt(t *testing.T) {
wcs := &modelv2.WorkspaceConfigs{
wcs := &modelv2.WorkspaceConfigs[string, *modelv2.WorkspaceConfig]{
Workspaces: map[string]*modelv2.WorkspaceConfig{
"ws-1": {
UpdatedAt: time.Date(2021, 1, 2, 0, 0, 0, 0, time.UTC),
Expand All @@ -21,6 +22,36 @@ func TestWorkspaceConfigsUpdatedAt(t *testing.T) {
},
}

updatedAt := wcs.UpdatedAt()
assert.Equal(t, time.Date(2021, 1, 2, 0, 0, 0, 0, time.UTC), updatedAt, "UpdatedAt should return the maximum of all workspace's UpdatedAt")
m := make(map[string]*modelv2.WorkspaceConfig, len(wcs.Workspaces))
for id, wc := range wcs.List() {
require.Equal(t, wcs.Workspaces[id], wc)
m[id] = wc
}

require.Len(t, m, 3)
require.Equal(t, wcs.Workspaces, m)

require.Equal(t, time.Date(2021, 1, 2, 0, 0, 0, 0, time.UTC), m["ws-1"].GetUpdatedAt())
require.Equal(t, time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC), m["ws-2"].GetUpdatedAt())
require.True(t, m["ws-3"].IsNil())

ws, ok := wcs.GetElementByKey("ws-1")
require.True(t, ok)
require.Equal(t, wcs.Workspaces["ws-1"], ws)

ws, ok = wcs.GetElementByKey("ws-2")
require.True(t, ok)
require.Equal(t, wcs.Workspaces["ws-2"], ws)

ws, ok = wcs.GetElementByKey("ws-3")
require.True(t, ok)
require.Nil(t, ws)

wcs.SetElementByKey("ws-3", &modelv2.WorkspaceConfig{
UpdatedAt: time.Date(2021, 1, 3, 0, 0, 0, 0, time.UTC),
})
ws, ok = wcs.GetElementByKey("ws-3")
require.True(t, ok)
require.Equal(t, wcs.Workspaces["ws-3"], ws)
require.Equal(t, time.Date(2021, 1, 3, 0, 0, 0, 0, time.UTC), wcs.Workspaces["ws-3"].GetUpdatedAt())
}

0 comments on commit aaac34a

Please sign in to comment.