Repository navigation
Expand file tree
/
Copy pathtesting.go
More file actions
61 lines (53 loc) · 2.36 KB
/
Copy pathtesting.go
File metadata and controls
61 lines (53 loc) · 2.36 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
52
53
54
55
56
57
58
59
60
61
package authbytecore
import (
"os"
"testing"
"github.com/go-quicktest/qt"
)
// TestApp constructs an App wired for tests. Backing stores are reached lazily,
// so this works without a live Valkey or PostgreSQL; a test that exercises
// login or sessions sets an in-memory session store (SetSessionStore) or names a
// live Valkey. opts are passed to New.
func TestApp(tb testing.TB, opts ...Option) *App {
tb.Helper()
app, err := startTestApp(tb, opts...)
qt.Assert(tb, qt.IsNil(err))
return app
}
// startTestApp is TestApp answering what New refuses, for a test of the start's
// own checks.
func startTestApp(tb testing.TB, opts ...Option) (*App, error) {
tb.Helper()
tb.Setenv("METRICS_ENABLED", "false")
tb.Setenv("ALLOW_EPHEMERAL_SIGNING_KEY", "true")
// SERVICE_NAME is required by go-platform-kit's base config. ENVIRONMENT is
// Azugo's own (development|test|staging|production) — it drives service.name's
// sibling service.environment and the OTel deployment.environment.
tb.Setenv("SERVICE_NAME", "authbyte")
tb.Setenv("ENVIRONMENT", "development")
if os.Getenv("AUTH_ISSUER_URL") == "" {
tb.Setenv("AUTH_ISSUER_URL", "http://localhost:8080")
}
// The eParaksts profile is the default upstream for tests. A test that puts the
// generic connector in the environment first (OIDC_UPSTREAM_AUTHORITY_URL, or
// the three explicit endpoints) gets that one instead — the service refuses to
// start with both families configured, so only one may be set here.
if os.Getenv("OIDC_UPSTREAM_AUTHORITY_URL") == "" && os.Getenv("OIDC_UPSTREAM_AUTHORIZE_URL") == "" {
tb.Setenv("EPARAKSTS_AUTHORITY_URL", "http://localhost:9999")
tb.Setenv("EPARAKSTS_CLIENT_ID", "test-client")
}
tb.Setenv("BASE_URL", "http://localhost:8080")
// The sign-in limit counts in the application's cache, which tests reach
// lazily or not at all; a test of the limit itself names a live Valkey.
if os.Getenv("SIGN_IN_RATE_LIMIT") == "" {
tb.Setenv("SIGN_IN_RATE_LIMIT", "0")
}
tb.Setenv("POSTGRES_DSN", "postgres://localhost:5432/authbyte_test?sslmode=disable")
// The service refuses an in-memory session store, so tests name a Valkey; it
// is dialled lazily, and tests that need the store set their own.
tb.Setenv("CACHE_TYPE", "redis")
if os.Getenv("CACHE_CONNECTION") == "" {
tb.Setenv("CACHE_CONNECTION", "redis://localhost:6379/0")
}
return New(nil, "0.0.0-test", opts...)
}