Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakule committed Jun 10, 2024
1 parent e527172 commit 277f217
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 102 deletions.
8 changes: 0 additions & 8 deletions lib/auth/userpreferences/userpreferencesv1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func TestService_GetUserPreferences(t *testing.T) {
req: &userpreferencesv1.GetUserPreferencesRequest{},
want: &userpreferencesv1.GetUserPreferencesResponse{
Preferences: &userpreferencesv1.UserPreferences{
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{},
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_DOCKED,
},
Theme: userpreferencesv1.Theme_THEME_UNSPECIFIED,
UnifiedResourcePreferences: &userpreferencesv1.UnifiedResourcePreferences{
DefaultTab: userpreferencesv1.DefaultTab_DEFAULT_TAB_ALL,
Expand Down Expand Up @@ -104,10 +100,6 @@ func TestService_UpsertUserPreferences(t *testing.T) {
t.Parallel()

defaultPreferences := &userpreferencesv1.UserPreferences{
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{},
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_DOCKED,
},
Theme: userpreferencesv1.Theme_THEME_LIGHT,
Onboard: &userpreferencesv1.OnboardUserPreferences{
PreferredResources: []userpreferencesv1.Resource{},
Expand Down
93 changes: 0 additions & 93 deletions lib/services/local/userpreferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package local_test

import (
"context"
"encoding/json"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -30,7 +29,6 @@ import (
"google.golang.org/protobuf/testing/protocmp"

userpreferencesv1 "github.com/gravitational/teleport/api/gen/proto/go/userpreferences/v1"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/services/local"
)
Expand Down Expand Up @@ -101,7 +99,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
},
},
expected: &userpreferencesv1.UserPreferences{
Assist: defaultPref.Assist,
Onboard: defaultPref.Onboard,
Theme: userpreferencesv1.Theme_THEME_DARK,
UnifiedResourcePreferences: defaultPref.UnifiedResourcePreferences,
Expand All @@ -118,7 +115,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
},
},
expected: &userpreferencesv1.UserPreferences{
Assist: defaultPref.Assist,
Onboard: defaultPref.Onboard,
Theme: defaultPref.Theme,
UnifiedResourcePreferences: &userpreferencesv1.UnifiedResourcePreferences{
Expand All @@ -140,7 +136,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
},
},
expected: &userpreferencesv1.UserPreferences{
Assist: defaultPref.Assist,
Onboard: defaultPref.Onboard,
Theme: defaultPref.Theme,
UnifiedResourcePreferences: &userpreferencesv1.UnifiedResourcePreferences{
Expand All @@ -152,50 +147,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
ClusterPreferences: defaultPref.ClusterPreferences,
},
},
{
name: "update the assist preferred logins only",
req: &userpreferencesv1.UpsertUserPreferencesRequest{
Preferences: &userpreferencesv1.UserPreferences{
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{"foo", "bar"},
},
Onboard: &userpreferencesv1.OnboardUserPreferences{
PreferredResources: []userpreferencesv1.Resource{},
MarketingParams: &userpreferencesv1.MarketingParams{},
},
},
},
expected: &userpreferencesv1.UserPreferences{
Theme: defaultPref.Theme,
UnifiedResourcePreferences: defaultPref.UnifiedResourcePreferences,
Onboard: defaultPref.Onboard,
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{"foo", "bar"},
ViewMode: defaultPref.Assist.ViewMode,
},
ClusterPreferences: defaultPref.ClusterPreferences,
},
},
{
name: "update the assist view mode only",
req: &userpreferencesv1.UpsertUserPreferencesRequest{
Preferences: &userpreferencesv1.UserPreferences{
Assist: &userpreferencesv1.AssistUserPreferences{
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_POPUP_EXPANDED_SIDEBAR_VISIBLE,
},
},
},
expected: &userpreferencesv1.UserPreferences{
Theme: defaultPref.Theme,
UnifiedResourcePreferences: defaultPref.UnifiedResourcePreferences,
Onboard: defaultPref.Onboard,
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: defaultPref.Assist.PreferredLogins,
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_POPUP_EXPANDED_SIDEBAR_VISIBLE,
},
ClusterPreferences: defaultPref.ClusterPreferences,
},
},
{
name: "update the onboard preference only",
req: &userpreferencesv1.UpsertUserPreferencesRequest{
Expand All @@ -212,7 +163,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
},
},
expected: &userpreferencesv1.UserPreferences{
Assist: defaultPref.Assist,
Theme: defaultPref.Theme,
UnifiedResourcePreferences: defaultPref.UnifiedResourcePreferences,
Onboard: &userpreferencesv1.OnboardUserPreferences{
Expand All @@ -239,7 +189,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
},
},
expected: &userpreferencesv1.UserPreferences{
Assist: defaultPref.Assist,
Theme: defaultPref.Theme,
UnifiedResourcePreferences: defaultPref.UnifiedResourcePreferences,
Onboard: defaultPref.Onboard,
Expand All @@ -261,10 +210,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED,
AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE,
},
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{"baz"},
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_POPUP,
},
Onboard: &userpreferencesv1.OnboardUserPreferences{
PreferredResources: []userpreferencesv1.Resource{userpreferencesv1.Resource_RESOURCE_KUBERNETES},
MarketingParams: &userpreferencesv1.MarketingParams{
Expand All @@ -289,10 +234,6 @@ func TestUserPreferencesCRUD(t *testing.T) {
LabelsViewMode: userpreferencesv1.LabelsViewMode_LABELS_VIEW_MODE_COLLAPSED,
AvailableResourceMode: userpreferencesv1.AvailableResourceMode_AVAILABLE_RESOURCE_MODE_NONE,
},
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{"baz"},
ViewMode: userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_POPUP,
},
Onboard: &userpreferencesv1.OnboardUserPreferences{
PreferredResources: []userpreferencesv1.Resource{userpreferencesv1.Resource_RESOURCE_KUBERNETES},
MarketingParams: &userpreferencesv1.MarketingParams{
Expand Down Expand Up @@ -335,37 +276,3 @@ func TestUserPreferencesCRUD(t *testing.T) {
})
}
}

func TestLayoutUpdate(t *testing.T) {
t.Parallel()

ctx := context.Background()
identity := newUserPreferencesService(t)

outdatedPrefs := &userpreferencesv1.UserPreferences{
Assist: &userpreferencesv1.AssistUserPreferences{
PreferredLogins: []string{"foo", "bar"},
},
}
val, err := json.Marshal(outdatedPrefs)
require.NoError(t, err)

// Insert the outdated preferences directly into the backend
// to simulate a previous version of the preferences.
_, err = identity.Put(ctx, backend.Item{
Key: backend.Key("user_preferences", "test"),
Value: val,
})
require.NoError(t, err)

// Get the preferences and ensure that the layout is updated.
prefs, err := identity.GetUserPreferences(ctx, "test")
require.NoError(t, err)
// The layout should be updated to the latest version (values should not be nil).
require.NotNil(t, prefs.Onboard)
// Non-existing values should be set to the default value.
require.Equal(t, userpreferencesv1.AssistViewMode_ASSIST_VIEW_MODE_DOCKED, prefs.Assist.ViewMode)
require.Equal(t, userpreferencesv1.Theme_THEME_UNSPECIFIED, prefs.Theme)
// Existing values should be preserved.
require.Equal(t, []string{"foo", "bar"}, prefs.Assist.PreferredLogins)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var rootPreferencesMock = &userpreferencesv1.UserPreferences{
}

var leafPreferencesMock = &userpreferencesv1.UserPreferences{
Assist: nil,
Onboard: nil,
ClusterPreferences: &userpreferencesv1.ClusterUserPreferences{
PinnedResources: &userpreferencesv1.PinnedResourcesUserPreferences{
Expand Down

0 comments on commit 277f217

Please sign in to comment.