Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pulak-opti committed Nov 23, 2023
1 parent 20758cc commit 2204260
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/handlers/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ func NewCache() *TestCache {
}

type TestDFSyncer struct {
syncCalled bool
syncCalled bool
subscribeCalled bool
}

func NewTestDFSyncer() *TestDFSyncer {
return &TestDFSyncer{
syncCalled: false,
syncCalled: false,
subscribeCalled: false,
}
}

Expand All @@ -63,6 +65,7 @@ func (t *TestDFSyncer) Sync(_ context.Context, _ string, _ string) error {
}

func (t *TestDFSyncer) Subscribe(_ context.Context, _ string) (chan string, error) {
t.subscribeCalled = true
return make(chan string), nil
}

Expand Down Expand Up @@ -267,3 +270,18 @@ func TestHandleWebhookWithDatafileSyncer(t *testing.T) {
assert.Equal(t, true, testCache.updateConfigsCalled)
assert.Equal(t, true, syncer.syncCalled)
}

func TestWebhookStartSyncer(t *testing.T) {
var testWebhookConfigs = map[int64]config.WebhookProject{
42: {
SDKKeys: []string{"myDatafile"},
Secret: "I am secret",
},
}
syncer := NewTestDFSyncer()

optlyHandler := NewWebhookHandler(nil, testWebhookConfigs, syncer)
err := optlyHandler.StartSyncer(context.Background())
assert.NoError(t, err)
assert.Equal(t, true, syncer.subscribeCalled)
}

0 comments on commit 2204260

Please sign in to comment.