diff --git a/.github/workflows/prjob_tests.yml b/.github/workflows/prjob_tests.yml index f054b78d6..c6016d936 100644 --- a/.github/workflows/prjob_tests.yml +++ b/.github/workflows/prjob_tests.yml @@ -41,8 +41,16 @@ jobs: - name: Install cover run: go get golang.org/x/tools/cmd/cover - - name: Tests - run: sudo V2_BOT_URL=http://localhost:3005 V2_BOT_TOKEN=xyzxyzxyz go test ./... -race -v -coverprofile=coverage.out && ./cover-check.sh coverage.out 8.4 + - name: Run Tests with Race Detector and Generate Coverage (Excluding Mocks) + run: | + PKGS=$(sudo go list ./... | grep -v '/mocks' | tr '\n' ',') + TEST_PKGS=$(sudo go list ./... | grep -v '/mocks') + + sudo V2_BOT_URL=http://localhost:3005 V2_BOT_TOKEN=xyzxyzxyz go test -race -coverprofile=coverage.out -coverpkg=$PKGS $TEST_PKGS + + - name: Show Coverage Summary + run: | + sudo go tool cover -func=coverage.out - name: Droping DB with docker compose run: docker compose -f ./docker/testdb-docker-compose.yml -p test_db down diff --git a/db/test_config.go b/db/test_config.go index c02588ef6..3aec802c5 100644 --- a/db/test_config.go +++ b/db/test_config.go @@ -39,14 +39,14 @@ func InitTestDB() { logger.Log.Info("DB CONNECTED") db.Exec(` - DO $$ BEGIN - ALTER TABLE tickets - ALTER COLUMN feature_uuid DROP NOT NULL, - ALTER COLUMN phase_uuid DROP NOT NULL; - EXCEPTION - WHEN others THEN null; - END $$; - `) + DO $$ BEGIN + ALTER TABLE tickets + ALTER COLUMN feature_uuid DROP NOT NULL, + ALTER COLUMN phase_uuid DROP NOT NULL; + EXCEPTION + WHEN others THEN null; + END $$; + `) // migrate table changes db.AutoMigrate(&Tribe{}) @@ -79,8 +79,8 @@ func InitTestDB() { db.AutoMigrate(&Bounty{}) db.AutoMigrate(&Notification{}) db.AutoMigrate(&BountyTiming{}) - db.AutoMigrate(&TextSnippet{}) db.AutoMigrate(&FileAsset{}) + db.AutoMigrate(&TextSnippet{}) people := TestDB.GetAllPeople() for _, p := range people { @@ -98,9 +98,16 @@ func DeleteAllChats() { TestDB.db.Exec("DELETE FROM chats") } -func CleanTestData() { +func DeleteAllBounties() { + TestDB.db.Exec("DELETE FROM bounty") +} + +func DeleteAllFeatureStories() { + TestDB.db.Exec("DELETE FROM feature_stories") +} - TestDB.DeleteAllBounties() +func CleanTestData() { + TestDB.db.Exec("DELETE FROM bounty") TestDB.db.Exec("DELETE FROM workspaces") @@ -115,12 +122,6 @@ func CleanTestData() { TestDB.db.Exec("DELETE FROM chats") TestDB.db.Exec("DELETE FROM notifications") - - TestDB.db.Exec("DELETE FROM feature_stories") - - TestDB.db.Exec("DELETE FROM text_snippets") - - TestDB.db.Exec("DELETE FROM file_assets") } func DeleteAllChatMessages() { diff --git a/handlers/bounties_test.go b/handlers/bounties_test.go index dd7ee3611..00fc69f2d 100644 --- a/handlers/bounties_test.go +++ b/handlers/bounties_test.go @@ -370,22 +370,17 @@ func createValidBounty() map[string]interface{} { } func TestGetWantedsHeader(t *testing.T) { - db.InitTestDB() + + db.CleanTestData() + defer func() { db.CleanTestData() db.CloseTestDB() }() - originalDB := db.DB - defer func() { - db.DB = originalDB - }() - db.DB = db.TestDB - db.CleanTestData() - tests := []struct { name string setupTestData func(t *testing.T) @@ -434,8 +429,10 @@ func TestGetWantedsHeader(t *testing.T) { }, }, { - name: "No Developers", - setupTestData: func(t *testing.T) {}, + name: "No Developers", + setupTestData: func(t *testing.T) { + db.DeleteAllBounties() + }, expectedStatus: http.StatusOK, validate: func(t *testing.T, response []byte) { var result struct { @@ -603,6 +600,8 @@ func TestGetWantedsHeader(t *testing.T) { } _, err := db.TestDB.CreateOrEditPerson(person) assert.NoError(t, err) + + db.DeleteAllBounties() }, expectedStatus: http.StatusOK, validate: func(t *testing.T, response []byte) { diff --git a/handlers/features_test.go b/handlers/features_test.go index b7fe1925e..cc55448bd 100644 --- a/handlers/features_test.go +++ b/handlers/features_test.go @@ -3691,8 +3691,8 @@ func TestGetFeatureStories(t *testing.T) { }) t.Run("Should not add user stories if stories array is empty", func(t *testing.T) { + db.DeleteAllFeatureStories() - db.CleanTestData() db.TestDB.CreateOrEditPerson(person) db.TestDB.CreateOrEditWorkspace(workspace) db.TestDB.CreateOrEditFeature(feature) @@ -3897,10 +3897,18 @@ func TestGetFeatureStories(t *testing.T) { }) t.Run("Duplicate Stories", func(t *testing.T) { - db.CleanTestData() db.TestDB.CreateOrEditPerson(person) db.TestDB.CreateOrEditWorkspace(workspace) + + feature := db.WorkspaceFeatures{ + Uuid: uuid.New().String(), + WorkspaceUuid: workspace.Uuid, + Name: "test-get-feature-stories-duplicate-content", + Url: "https://github.com/test-get-feature-stories-feature-url", + Priority: 0, + } + db.TestDB.CreateOrEditFeature(feature) duplicateStory := db.FeatureStories{