xonecas.io
5011
Sp

scrap-paper / commit 997caeb

test: use a test db for running tests

Sean2025-03-24 997caeb02790ab971231a9b8b5f11ed9539a53fe parent c212155

2 files changed

scrap-paper/scrap_paper.go+4−4
@@ -7,8 +7,8 @@ var pgsql = sqldb.NewDatabase("scrap_paper", sqldb.DatabaseConfig{
77 })
88
99 //encore:service
10-type ScrapPaperService struct {}
10+type ScrapPaperService struct{}
1111
12-func NewScrapPaperService() *ScrapPaperService {
13- return &ScrapPaperService{}
14-}
12+func initScrapPaperService() (*ScrapPaperService, error) {
13+ return &ScrapPaperService{}, nil
14+}
scrap-paper/storage_test.go+9−4
@@ -5,13 +5,18 @@ import (
55 "testing"
66
77 scrap_paper "encore.app/scrap-paper"
8+ "encore.dev/et"
89 )
910
1011 func TestScrapPaperCRUD(t *testing.T) {
1112 ctx := context.Background()
1213
14+ if _, err := et.NewTestDatabase(ctx, "scrap_paper"); err != nil {
15+ t.Fatalf("failed to create test database: %v", err)
16+ }
17+
1318 scrapPaper := &scrap_paper.ScrapPaper{
14- Content: "Hello test, test.",
19+ Content: "Hello test, test.",
1520 IsPrivate: false,
1621 }
1722
@@ -24,11 +29,11 @@ func TestScrapPaperCRUD(t *testing.T) {
2429 if scrapPaper.Id == "" {
2530 t.Fatalf("scrap paper id is empty")
2631 }
27-
32+
2833 if scrapPaper.Content != "Hello test, test." {
2934 t.Fatalf("scrap paper content is not Hello test, test.: %v", scrapPaper.Content)
3035 }
31-
36+
3237 if scrapPaper.IsPrivate != false {
3338 t.Fatalf("scrap paper private is not false: %v", scrapPaper.IsPrivate)
3439 }
@@ -43,7 +48,7 @@ func TestScrapPaperCRUD(t *testing.T) {
4348 if scrapPaper.Id == "" {
4449 t.Fatalf("scrap paper id is empty")
4550 }
46-
51+
4752 if scrapPaper.Content != "Hello test, test." {
4853 t.Fatalf("scrap paper content is not Hello test, test.: %v", scrapPaper.Content)
4954 }