-
Notifications
You must be signed in to change notification settings - Fork 980
test: Use a template to prevent migrations from running for every test #2462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d57cbd1
9eef36a
5ca6beb
6f05b7d
21ecb38
6546be9
ee3f32b
3dff1c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,14 +112,6 @@ site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk | |
test: test-clean | ||
gotestsum -- -v -short ./... | ||
|
||
.PHONY: test-postgres | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why drop this make target? It's important for developers to be able to more-or-less exactly (closer the better) reproduce CI build/test locally so that we can reproduce errors that CI discovers. To that end, you want to keep all the logic in the Makefile or build scripts and then the CI just executes those targets/scripts. This PR takes us in the opposite direction, removing stuff from make and baking it into the CI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes an external PostgreSQL instance is running, which breaks a pretty fundamental rule of I'm fine to move this in a script, but it's not idiomatic to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair. Would be nice to have a |
||
test-postgres: test-clean | ||
DB=ci gotestsum --junitfile="gotests.xml" --packages="./..." -- \ | ||
-covermode=atomic -coverprofile="gotests.coverage" -timeout=30m \ | ||
-coverpkg=./...,github.com/coder/coder/codersdk \ | ||
-count=1 -race -failfast | ||
|
||
|
||
.PHONY: test-postgres-docker | ||
test-postgres-docker: | ||
docker run \ | ||
|
@@ -131,7 +123,7 @@ test-postgres-docker: | |
--name test-postgres-docker \ | ||
--restart unless-stopped \ | ||
--detach \ | ||
postgres:11 \ | ||
postgres:13 \ | ||
-c shared_buffers=1GB \ | ||
-c max_connections=1000 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/cryptorand" | ||
) | ||
|
||
func main() { | ||
dbURL := "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable" | ||
db, err := sql.Open("postgres", dbURL) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer db.Close() | ||
|
||
dbName, err := cryptorand.StringCharset(cryptorand.Lower, 10) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
dbName = "ci" + dbName | ||
_, err = db.Exec("CREATE DATABASE " + dbName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = database.MigrateUp(db) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
_, _ = fmt.Println(dbName) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.