Skip to content

Commit a1b5849

Browse files
committed
update unit test
1 parent 0e8a997 commit a1b5849

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pkg/handlers/notification_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package handlers
2020
import (
2121
"context"
2222
"errors"
23+
"fmt"
2324
"net/http"
2425
"net/http/httptest"
2526
"reflect"
@@ -376,6 +377,7 @@ func TestRedisNotificationReceiver(t *testing.T) {
376377
}
377378
type args struct {
378379
conf config.SyncConfig
380+
ctx context.Context
379381
}
380382
tests := []struct {
381383
name string
@@ -384,14 +386,20 @@ func TestRedisNotificationReceiver(t *testing.T) {
384386
}{
385387
{
386388
name: "Test happy path",
387-
args: args{conf: conf},
389+
args: args{
390+
conf: conf,
391+
ctx: context.WithValue(context.Background(), SDKKey, "random-sdk-key-1"),
392+
},
388393
want: func(ctx context.Context) (<-chan syncer.Event, error) {
389394
return make(<-chan syncer.Event), nil
390395
},
391396
},
392397
{
393398
name: "Test empty config",
394-
args: args{conf: config.SyncConfig{}},
399+
args: args{
400+
conf: config.SyncConfig{},
401+
ctx: context.WithValue(context.Background(), SDKKey, "random-sdk-key-2"),
402+
},
395403
want: func(ctx context.Context) (<-chan syncer.Event, error) {
396404
return nil, errors.New("error")
397405
},
@@ -404,15 +412,16 @@ func TestRedisNotificationReceiver(t *testing.T) {
404412
t.Errorf("RedisNotificationReceiver() = %v, want %v", got, tt.want)
405413
}
406414

407-
ch1, err1 := got(context.TODO())
408-
ch2, err2 := tt.want(context.TODO())
415+
ch1, err1 := got(tt.args.ctx)
416+
ch2, err2 := tt.want(tt.args.ctx)
409417

410418
if reflect.TypeOf(err1) != reflect.TypeOf(err2) {
419+
fmt.Println(err1, err2)
411420
t.Errorf("error type not matched")
412421
}
413422

414423
if reflect.TypeOf(ch1) != reflect.TypeOf(ch2) {
415-
t.Errorf("error type not matched")
424+
t.Errorf("channel type not matched")
416425
}
417426
})
418427
}
157 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)