Skip to content

Commit

Permalink
Add test for knownSubsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Jul 17, 2024
1 parent 38036fb commit b50678e
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ee/control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,71 @@ func TestControlServicePersistLastFetched(t *testing.T) {
}
}

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

for _, tt := range []struct {
testCaseName string
subsystemName string
consumers []string
subscribers []string
subsystemKnown bool
}{
{
testCaseName: "subsystem in consumers",
subsystemName: "subsystem_to_query",
consumers: []string{"subsystem_to_query", "some_other_subsystem"},
subscribers: []string{"some_other_subsystem", "a_third_subsystem"},
subsystemKnown: true,
},
{
testCaseName: "subsystem in subscribers",
subsystemName: "subsystem_to_query",
consumers: []string{"some_other_subsystem"},
subscribers: []string{"some_other_subsystem", "subsystem_to_query"},
subsystemKnown: true,
},
{
testCaseName: "subsystem in consumers and subscribers",
subsystemName: "subsystem_to_query",
consumers: []string{"subsystem_to_query", "some_other_subsystem"},
subscribers: []string{"some_other_subsystem", "subsystem_to_query"},
subsystemKnown: true,
},
{
testCaseName: "subsystem is unknown",
subsystemName: "subsystem_to_query",
consumers: []string{"some_other_subsystem", "another_test_subsystem"},
subscribers: []string{"some_other_subsystem"},
subsystemKnown: false,
},
} {
tt := tt
t.Run(tt.testCaseName, func(t *testing.T) {
t.Parallel()

mockKnapsack := typesMocks.NewKnapsack(t)
mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.ControlRequestInterval)
mockKnapsack.On("ControlRequestInterval").Return(60 * time.Second)
mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())

controlOpts := []Option{}
cs := New(mockKnapsack, nil, controlOpts...)

// Register known consumers and subscribers
for _, c := range tt.consumers {
require.NoError(t, cs.RegisterConsumer(c, &mockConsumer{}))
}
for _, s := range tt.subscribers {
cs.RegisterSubscriber(s, &mockSubscriber{})
}

known := cs.knownSubsystem(tt.subsystemName)
require.Equal(t, tt.subsystemKnown, known)
})
}
}

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

Expand Down

0 comments on commit b50678e

Please sign in to comment.