-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_example_test.go
More file actions
51 lines (45 loc) · 1.32 KB
/
Copy pathapp_example_test.go
File metadata and controls
51 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"context"
"github.com/sedmess/go-ctx-base/utils/channels"
"github.com/sedmess/go-ctx/ctx"
"github.com/sedmess/go-ctx/ctx/ctx_testing"
"github.com/sedmess/go-ctx/ctx/logger"
"os"
"testing"
)
type messageServiceStub struct {
l logger.Logger `ctx:""`
}
func (s *messageServiceStub) SaveMessage(string, string, string) error {
s.l.Info("SaveMessage stub")
return nil
}
func (s *messageServiceStub) GetMessages(string, int64) channels.StreamingChan[Message] {
s.l.Info("GetMessage stub")
return channels.CreateChannel(func(sink func(data Message, context context.Context) bool) error {
return nil
})
}
func TestMain(m *testing.M) {
os.Exit(ctx_testing.CreateTestingApplication(Packages...).
WithParameter("DB_SQLITE_PATH", "file::memory:?cache=shared").
WithParameter("HTTP_LISTEN", "127.0.0.1:57650").
WithParameter("HTTP_AUTH_TOKENS", "token,token1,token2").
WithTestingService(ctx_testing.Instead[MessageService](&messageServiceStub{})).
Run(m.Run))
}
func Test_MessageController(t *testing.T) {
messageController, ok := ctx.GetTypedService[*messageController]()
if !ok || messageController == nil {
t.FailNow()
}
messages := messageController.messageService.GetMessages("", 0)
slice, err := messages.CollectToSlice()
if err != nil {
t.FailNow()
}
if len(slice) > 0 {
t.FailNow()
}
}