Skip to content

Commit

Permalink
Add test coverage to prevent issues like #241 in the future (#244)
Browse files Browse the repository at this point in the history
* Add test coverage to prevent issues like #241 in the future

* Add debugging

* Fix location of HISHTORY_COMPOSE_TEST var

* Enable tmate for failures

* update

* Re-comment tmate
  • Loading branch information
ddworken authored Sep 7, 2024
1 parent a987801 commit 11fc92e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
sudo chmod 0755 -R /usr/share/zsh/ # Work around a weird bug where zsh on ubuntu actions gives that diretory 0777 which makes zsh refuse to start
sudo hostname ghaction-runner-hostname # Set a consistent hostname so we can run tests that depend on it
docker compose -f backend/server/docker-compose.yml build
docker compose -f backend/server/docker-compose.yml up -d
HISHTORY_COMPOSE_TEST=1 docker compose -f backend/server/docker-compose.yml up -d
export HISHTORY_SERVER=http://localhost
go build
./hishtory install
Expand All @@ -48,8 +48,12 @@ jobs:
! (./hishtory export | grep "ls -Slah /")
# Assert that the entry is syncing properly
./hishtory status -v | grep 'Sync Status: Synced'
# And that we are properly using the self-hosted server
./hishtory status -v | grep 'Sync Server: http://localhost'
# Show the full status output for debugging
./hishtory status -v
# - name: Setup tmate session
# if: ${{ failure() }}
# # if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true
1 change: 1 addition & 0 deletions backend/server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
delay: 3s
environment:
HISHTORY_POSTGRES_DB: postgresql://postgres:TODO_YOUR_POSTGRES_PASSWORD_HERE@postgres:5432/hishtory?sslmode=disable
HISHTORY_COMPOSE_TEST: $HISHTORY_COMPOSE_TEST
ports:
- 80:8080
volumes:
Expand Down
14 changes: 13 additions & 1 deletion backend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,19 @@ func OpenDB() (*database.DB, error) {
}
err = db.CreateIndices()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create indices: %w", err)
}
}
if os.Getenv("HISHTORY_COMPOSE_TEST") != "" {
// Run an extra round of migrations to test the migration code path to prevent issues like #241
fmt.Println("AutoMigrating DB tables a second time for test coverage")
err := db.AddDatabaseTables()
if err != nil {
return nil, fmt.Errorf("failed to create underlying DB tables: %w", err)
}
err = db.CreateIndices()
if err != nil {
return nil, fmt.Errorf("failed to create indices: %w", err)
}
}
return db, nil
Expand Down

0 comments on commit 11fc92e

Please sign in to comment.