Skip to content

Commit 6be42ae

Browse files
committed
Fix test
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 9acae13 commit 6be42ae

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

pkg/teamloader/filter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ type filterTools struct {
4242
exclude bool
4343
}
4444

45+
// Verify interface compliance
46+
var _ tools.Instructable = (*filterTools)(nil)
47+
48+
// Instructions implements tools.Instructable by delegating to the inner toolset.
49+
func (f *filterTools) Instructions() string {
50+
return tools.GetInstructions(f.ToolSet)
51+
}
52+
4553
func (f *filterTools) Tools(ctx context.Context) ([]tools.Tool, error) {
4654
allTools, err := f.ToolSet.Tools(ctx)
4755
if err != nil {

pkg/teamloader/filter_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,51 @@ func TestWithToolsFilter_CaseSensitive(t *testing.T) {
119119
require.Len(t, result, 1)
120120
assert.Equal(t, "tool1", result[0].Name)
121121
}
122+
123+
type instructableToolSet struct {
124+
mockToolSet
125+
instructions string
126+
}
127+
128+
func (i *instructableToolSet) Instructions() string {
129+
return i.instructions
130+
}
131+
132+
func TestWithToolsFilter_InstructablePassthrough(t *testing.T) {
133+
// Test that filtering preserves instructions from inner toolset
134+
inner := &instructableToolSet{
135+
mockToolSet: mockToolSet{
136+
toolsFunc: func(context.Context) ([]tools.Tool, error) {
137+
return []tools.Tool{{Name: "tool1"}, {Name: "tool2"}}, nil
138+
},
139+
},
140+
instructions: "Test instructions for the toolset",
141+
}
142+
143+
wrapped := WithToolsFilter(inner, "tool1")
144+
145+
// Verify instructions are preserved through the filter wrapper
146+
instructions := tools.GetInstructions(wrapped)
147+
assert.Equal(t, "Test instructions for the toolset", instructions)
148+
149+
// Verify filtering still works
150+
result, err := wrapped.Tools(t.Context())
151+
require.NoError(t, err)
152+
require.Len(t, result, 1)
153+
assert.Equal(t, "tool1", result[0].Name)
154+
}
155+
156+
func TestWithToolsFilter_NonInstructableInner(t *testing.T) {
157+
// Test that filter works with toolsets that don't implement Instructable
158+
inner := &mockToolSet{
159+
toolsFunc: func(context.Context) ([]tools.Tool, error) {
160+
return []tools.Tool{{Name: "tool1"}}, nil
161+
},
162+
}
163+
164+
wrapped := WithToolsFilter(inner, "tool1")
165+
166+
// Verify instructions are empty for non-instructable inner toolset
167+
instructions := tools.GetInstructions(wrapped)
168+
assert.Empty(t, instructions)
169+
}

0 commit comments

Comments
 (0)