docs(flare,kiosk,lagoon): compile README Go examples via src= (quick-261118-qsd)
- flare: send region run by TestDocsNotifyReply against a loopback TLS push service; blogSubscriptions and the publish-source region run by TestDocsSubscriptionSource on a Postgres container (skips under -short) - kiosk: write, newest and client regions run by TestDocsWriteManifest (a copy of the literal fixture), ExampleVersionsResponse and TestDocsBlogReleases (httptest registry); the CheckT fence reuses TestPluginManifest - lagoon: new open region run by TestDocsOpenFromApp (DocsDSN added to export_docs_test.go); the model, create-post, on-database, publish and migrations fences reuse the Database pages' targets
This commit is contained in:
@@ -3,6 +3,7 @@ package lagoon_test
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
@@ -645,3 +647,49 @@ func TestDocsModelDeclarations(t *testing.T) {
|
||||
t.Fatalf("Migrations() = %d, want 2", n)
|
||||
}
|
||||
}
|
||||
|
||||
// openDatabase opens the shared pool from the app's config at boot and
|
||||
// publishes it, so plugins and handlers reuse the same handles.
|
||||
func openDatabase(ctx context.Context, app *backpack.App) error {
|
||||
// docs:start open
|
||||
sqlDB, gdb, err := lagoon.OpenFromApp(ctx, app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := lagoon.Publish(app, sqlDB, gdb); err != nil {
|
||||
return err
|
||||
}
|
||||
// docs:end open
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestDocsOpenFromApp runs the open region on a config whose database.dsn
|
||||
// and app.key come from the environment.
|
||||
func TestDocsOpenFromApp(t *testing.T) {
|
||||
dsn := lagoon.DocsDSN(t, "docs_open")
|
||||
key := base64.StdEncoding.EncodeToString([]byte("0123456789abcdef0123456789abcdef"))
|
||||
cfg, err := compass.Open(compass.Options{Dir: t.TempDir(), Environ: []string{
|
||||
"SUMMER_DATABASE__DSN=" + dsn,
|
||||
"SUMMER_APP__KEY=" + key,
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app := backpack.New(cfg)
|
||||
if err := openDatabase(t.Context(), app); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sqlDB, ok := app.Lookup[*sql.DB]()
|
||||
if !ok {
|
||||
t.Fatal("no *sql.DB published")
|
||||
}
|
||||
t.Cleanup(func() { _ = sqlDB.Close() })
|
||||
gdb, ok := app.Lookup[*gorm.DB]()
|
||||
if !ok {
|
||||
t.Fatal("no *gorm.DB published")
|
||||
}
|
||||
var one int
|
||||
if err := gdb.WithContext(t.Context()).Raw(`SELECT 1`).Scan(&one).Error; err != nil || one != 1 {
|
||||
t.Fatalf("SELECT 1 = %d, %v", one, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user