diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..ab533fad --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,69 @@ +name: Run Go Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + types: + - ready_for_review + - opened + - reopened + - synchronize + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + services: + # Postgres service container + postgres: + image: postgres:16 + env: + # Specify the password for Postgres superuser. + POSTGRES_PASSWORD: a!b@c$d()e*_,/:;=?@ff[]22 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.23.x' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Install gotestsum + run: go install gotest.tools/gotestsum@latest + + - name: Run tests + run: gotestsum --format github-action + working-directory: ./dbos + env: + PGPASSWORD: a!b@c$d()e*_,/:;=?@ff[]22 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/dbos/system_database.go b/dbos/system_database.go index ceb4a10b..05399cb1 100644 --- a/dbos/system_database.go +++ b/dbos/system_database.go @@ -5,6 +5,7 @@ import ( "embed" "errors" "fmt" + "net/url" "os" "strings" "time" @@ -121,7 +122,9 @@ func NewSystemDatabase() (SystemDatabase, error) { // TODO: pass proper config databaseURL := os.Getenv("DBOS_DATABASE_URL") if databaseURL == "" { - return nil, NewInitializationError("DBOS_DATABASE_URL environment variable is required") + fmt.Println("DBOS_DATABASE_URL not set, using default: postgres://postgres:${PGPASSWORD}@localhost:5432/dbos?sslmode=disable") + password := url.QueryEscape(os.Getenv("PGPASSWORD")) + databaseURL = fmt.Sprintf("postgres://postgres:%s@localhost:5432/dbos?sslmode=disable", password) } // Create the database if it doesn't exist diff --git a/dbos/utils_test.go b/dbos/utils_test.go index d1877a4b..b7c6d667 100644 --- a/dbos/utils_test.go +++ b/dbos/utils_test.go @@ -2,6 +2,8 @@ package dbos import ( "context" + "fmt" + "net/url" "os" "sync" "testing" @@ -16,7 +18,8 @@ func setupDBOS(t *testing.T) { databaseURL := os.Getenv("DBOS_DATABASE_URL") if databaseURL == "" { - t.Skip("DBOS_DATABASE_URL not set, skipping integration test") + password := url.QueryEscape(os.Getenv("PGPASSWORD")) + databaseURL = fmt.Sprintf("postgres://postgres:%s@localhost:5432/dbos?sslmode=disable", password) } // Clean up the test database