MCPcopy
hub / github.com/ory/kratos / createCleanDatabases

Function createCleanDatabases

persistence/sql/persister_test.go:96–172  ·  view source on GitHub ↗
(t testing.TB)

Source from the content-addressed store, hash-verified

94}
95
96func createCleanDatabases(t testing.TB) map[string]string {
97 conns := map[string]string{
98 "sqlite": dbal.NewSQLiteTestDatabase(t),
99 }
100 connsMtx := sync.Mutex{}
101
102 if !testing.Short() {
103 funcs := map[string]func(t testing.TB) string{
104 "postgres": func(t testing.TB) string {
105 return dockertest.RunTestPostgreSQLWithVersion(t, "16")
106 },
107 "mysql": func(t testing.TB) string {
108 return dockertest.RunTestMySQLWithVersion(t, "8.4")
109 },
110 "cockroach": newLocalTestCRDBServer,
111 }
112
113 var wg sync.WaitGroup
114 wg.Add(len(funcs))
115
116 for k, f := range funcs {
117 go func(s string, f func(t testing.TB) string) {
118 defer wg.Done()
119 db := f(t)
120 connsMtx.Lock()
121 conns[s] = db
122 connsMtx.Unlock()
123 }(k, f)
124 }
125
126 wg.Wait()
127 }
128
129 ps := make(map[string]string, len(conns))
130 psMtx := sync.Mutex{}
131
132 var wg sync.WaitGroup
133 wg.Add(len(conns))
134 for name, dsn := range conns {
135 go func(name, dsn string) {
136 defer wg.Done()
137
138 if name != "sqlite" {
139 require.EventuallyWithT(t, func(t *assert.CollectT) {
140 c, err := pop.NewConnection(&pop.ConnectionDetails{URL: dsn})
141 require.NoError(t, err)
142 require.NoError(t, c.Open())
143 dbName := "testdb" + strings.ReplaceAll(x.NewUUID().String(), "-", "")
144 require.NoError(t, c.RawQuery("CREATE DATABASE "+dbName).Exec())
145 dsn = regexp.MustCompile(`/[a-z0-9]+\?`).ReplaceAllString(dsn, "/"+dbName+"?")
146 }, 20*time.Second, 100*time.Millisecond)
147 }
148
149 t.Logf("Connecting to %s: %s", name, dsn)
150
151 _, reg := pkg.NewRegistryDefaultWithDSN(t, dsn)
152 p := reg.Persister().(*sql.Persister)
153

Callers 2

TestPersisterFunction · 0.85

Calls 13

NewUUIDFunction · 0.92
plFunction · 0.85
HasPendingMethod · 0.80
StringMethod · 0.65
ExecMethod · 0.65
PersisterMethod · 0.65
SetLoggerMethod · 0.65
MigrateUpMethod · 0.65
MigrationStatusMethod · 0.65
AddMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected