From 2182fc469cdccc517550233d00101bcc7918678d Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 1 Apr 2026 14:04:21 -0400 Subject: [PATCH] fix: update UI tests to use test workspace --- internal/ui/model/ui_test.go | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/internal/ui/model/ui_test.go b/internal/ui/model/ui_test.go index 84b216e5470619e08af404967a347a831b53bcc2..4032c80a059b3b41f1ea2814cd87e8749e7ff100 100644 --- a/internal/ui/model/ui_test.go +++ b/internal/ui/model/ui_test.go @@ -1,15 +1,13 @@ package model import ( - "reflect" "testing" - "unsafe" "charm.land/catwalk/pkg/catwalk" - "github.com/charmbracelet/crush/internal/app" "github.com/charmbracelet/crush/internal/config" "github.com/charmbracelet/crush/internal/csync" "github.com/charmbracelet/crush/internal/ui/common" + "github.com/charmbracelet/crush/internal/workspace" "github.com/stretchr/testify/require" ) @@ -79,29 +77,19 @@ func TestCurrentModelSupportsImages(t *testing.T) { func newTestUIWithConfig(t *testing.T, cfg *config.Config) *UI { t.Helper() - store := &config.ConfigStore{} - setUnexportedField(t, store, "config", cfg) - - appInstance := &app.App{} - setUnexportedField(t, appInstance, "config", store) - return &UI{ com: &common.Common{ - App: appInstance, + Workspace: &testWorkspace{cfg: cfg}, }, } } -func setUnexportedField(t *testing.T, target any, name string, value any) { - t.Helper() - - v := reflect.ValueOf(target) - require.Equal(t, reflect.Pointer, v.Kind()) - require.False(t, v.IsNil()) - - field := v.Elem().FieldByName(name) - require.Truef(t, field.IsValid(), "field %q not found", name) +// testWorkspace is a minimal [workspace.Workspace] stub for unit tests. +type testWorkspace struct { + workspace.Workspace + cfg *config.Config +} - fieldValue := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem() - fieldValue.Set(reflect.ValueOf(value)) +func (w *testWorkspace) Config() *config.Config { + return w.cfg }