...
1 package lighthouse
2
3 import (
4 "database/sql"
5 "fmt"
6 "testing"
7 "time"
8
9 "github.com/go-logr/logr"
10 "github.com/stretchr/testify/suite"
11
12 "edge-infra.dev/pkg/edge/api/testutils/seededpostgres"
13 "edge-infra.dev/pkg/lib/logging"
14 "edge-infra.dev/test/framework"
15 )
16
17 const (
18 databaseHost = "localhost"
19 databaseName = "lighthouse"
20 databaseUser = "test"
21 databasePassword = "12345"
22 testProjectID = "ret-dev-test"
23 testPubsubTopic = "test-stream"
24 testPubsubSubscription = "test-subscription"
25 insertOperation = "INSERT"
26 )
27
28
29
30 type Suite struct {
31 *framework.Framework
32 SeededPostgres *seededpostgres.SeededPostgres
33 DB *sql.DB
34 Host string
35 Name string
36 User string
37 Password string
38 Port string
39 ProjectID string
40 TopicID string
41 SubscriptionID string
42 AckDeadline time.Duration
43 Log logr.Logger
44 InsertOperation string
45 }
46
47 func SetupLighthouseSuite() (*Suite, error) {
48 f := framework.New("lighthouse-test")
49
50 sp, err := seededpostgres.NewWithUser(databaseName, databaseUser, databasePassword)
51 if err != nil {
52 return nil, err
53 }
54 db, err := sp.DB()
55 if err != nil {
56 _ = sp.Close()
57 return nil, err
58 }
59
60 return &Suite{
61 Framework: f,
62 SeededPostgres: sp,
63 Host: databaseHost,
64 Name: databaseName,
65 User: databaseUser,
66 Password: databasePassword,
67 Port: fmt.Sprint(sp.Port()),
68 DB: db,
69 ProjectID: "ret-dev-test",
70 TopicID: "test-stream",
71 SubscriptionID: "test-subscription",
72 AckDeadline: 25 * time.Second,
73 Log: logging.NewLogger().WithName("lighthouse"),
74 InsertOperation: insertOperation,
75 }, nil
76 }
77
78 func TestLighthouse(t *testing.T) {
79 s, err := SetupLighthouseSuite()
80 if err != nil {
81 t.Fatal(err)
82 }
83 suite.Run(t, s)
84 t.Cleanup(func() {
85 err := s.DB.Close()
86 if err != nil {
87 panic(err)
88 }
89 err = s.SeededPostgres.Close()
90 if err != nil {
91 panic(err)
92 }
93 })
94 }
95
View as plain text