Skip to content

Commit

Permalink
Merge pull request #1211 from France-ioi/testoutput
Browse files Browse the repository at this point in the history
Move&rename testhelpers/SuppressOutputIfPasses(), suppress output of more tests
  • Loading branch information
zenovich authored Nov 12, 2024
2 parents 3dc248a + 23c0576 commit 68f222d
Show file tree
Hide file tree
Showing 46 changed files with 442 additions and 100 deletions.
3 changes: 3 additions & 0 deletions app/api/auth/refresh_access_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/France-ioi/AlgoreaBackend/v2/app/auth"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"

"github.com/DATA-DOG/go-sqlmock"
"github.com/go-chi/chi"
Expand All @@ -22,6 +23,8 @@ import (
)

func TestService_refreshAccessToken_NotAllowRefreshTokenRaces(t *testing.T) {
testoutput.SuppressIfPasses(t)

expectedClientID := "1234"
expectedClientSecret := "secret"
loginModuleStubServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 2 additions & 1 deletion app/api/currentuser/current_user_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/app/service"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func Test_checkPreconditionsForGroupRequests(t *testing.T) {
Expand Down Expand Up @@ -184,7 +185,7 @@ func Test_checkPreconditionsForGroupRequests(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testhelpers.SuppressOutputIfPasses(t)
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(tt.fixture)
defer func() { _ = db.Close() }()
Expand Down
3 changes: 2 additions & 1 deletion app/api/groups/create_invitations_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/France-ioi/AlgoreaBackend/v2/app/api/groups"
"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func Test_filterOtherTeamsMembersOut(t *testing.T) {
Expand Down Expand Up @@ -243,7 +244,7 @@ func Test_filterOtherTeamsMembersOut(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testhelpers.SuppressOutputIfPasses(t)
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(tt.fixture)
defer func() { _ = db.Close() }()
Expand Down
3 changes: 2 additions & 1 deletion app/api/items/path_from_root_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/France-ioi/AlgoreaBackend/v2/app/api/items"
"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func Test_FindItemPath(t *testing.T) {
Expand Down Expand Up @@ -811,7 +812,7 @@ func Test_FindItemPath(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testhelpers.SuppressOutputIfPasses(t)
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(globalFixture, tt.fixture)
defer func() { _ = db.Close() }()
Expand Down
3 changes: 2 additions & 1 deletion app/api/items/start_result_path_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/France-ioi/AlgoreaBackend/v2/app/api/items"
"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func Test_getDataForResultPathStart(t *testing.T) {
Expand Down Expand Up @@ -438,7 +439,7 @@ func Test_getDataForResultPathStart(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testhelpers.SuppressOutputIfPasses(t)
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(globalFixture, tt.fixture)
defer func() { _ = db.Close() }()
Expand Down
5 changes: 5 additions & 0 deletions app/database/answer_store_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (

"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func TestAnswerStore_SubmitNewAnswer(t *testing.T) {
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(`
groups: [{id: 121}]
users: [{group_id: 121}]
Expand All @@ -34,6 +37,8 @@ func TestAnswerStore_SubmitNewAnswer(t *testing.T) {
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
testoutput.SuppressIfPasses(t)

newID, err := answerStore.SubmitNewAnswer(test.authorID, test.participantID, test.attemptID, test.itemID, test.answer)

assert.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions app/database/attempt_store_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/golang"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

type resultType struct {
Expand All @@ -31,6 +32,8 @@ type attemptType struct {
}

func TestAttemptStore_CreateNew_CreatesNewAttempt(t *testing.T) {
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(`
groups:
- {id: 10}
Expand Down
5 changes: 5 additions & 0 deletions app/database/badges_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func TestGroupStore_StoreBadges(t *testing.T) {
Expand Down Expand Up @@ -268,6 +269,8 @@ func TestGroupStore_StoreBadges(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(`
groups: [{id: 5}]
users: [{group_id: 5}]` + tt.fixture)
Expand Down Expand Up @@ -379,6 +382,8 @@ func TestGroupStore_StoreBadges(t *testing.T) {
}

func TestGroupStore_StoreBadge_PropagatesResults(t *testing.T) {
testoutput.SuppressIfPasses(t)

db := testhelpers.SetupDBWithFixtureString(`
groups: [{id: 1, text_id: badge_url}, {id: 5}, {id: 6}]
users: [{group_id: 5, login: john}, {group_id: 6, login: jane}]
Expand Down
3 changes: 3 additions & 0 deletions app/database/data_store_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (

"github.com/France-ioi/AlgoreaBackend/v2/app/database"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func TestDataStore_WithForeignKeyChecksDisabled(t *testing.T) {
testoutput.SuppressIfPasses(t)

rawDB, err := testhelpers.OpenRawDBConnection()
if err != nil {
assert.FailNow(t, err.Error())
Expand Down
43 changes: 43 additions & 0 deletions app/database/data_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/France-ioi/AlgoreaBackend/v2/golang"
"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func TestDataStore_StoreConstructorsSetTablesCorrectly(t *testing.T) {
Expand Down Expand Up @@ -54,6 +55,8 @@ func TestDataStore_StoreConstructorsSetTablesCorrectly(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()
mock.ExpectQuery("SELECT \\* FROM " + tt.wantTable).
Expand Down Expand Up @@ -114,6 +117,8 @@ func TestDataStore_StoreConstructorsReturnObjectsOfRightTypes(t *testing.T) {
}

func TestDataStore_ByID(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -138,6 +143,8 @@ func TestDataStore_ByID_ForAbstractDataStore(t *testing.T) {
}

func TestDataStore_InTransaction_NoErrors(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down Expand Up @@ -166,6 +173,8 @@ func TestDataStore_InTransaction_NoErrors(t *testing.T) {
}

func TestDataStore_InTransaction_DBError(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -190,6 +199,8 @@ func TestDataStore_InTransaction_DBError(t *testing.T) {
}

func TestDataStore_InTransaction_ContextAndTxOptions(t *testing.T) {
testoutput.SuppressIfPasses(t)

var callsCount int

type ctxKey string
Expand Down Expand Up @@ -217,6 +228,8 @@ func TestDataStore_InTransaction_ContextAndTxOptions(t *testing.T) {
}

func TestDataStore_InTransaction_ForcesTransactionRetryingForTestingPurposes(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -238,6 +251,8 @@ func TestDataStore_InTransaction_ForcesTransactionRetryingForTestingPurposes(t *
}

func TestDataStore_InTransaction_ForcesTransactionRetryingForTestingPurposes_Hooks(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down Expand Up @@ -271,6 +286,8 @@ func TestDataStore_InTransaction_ForcesTransactionRetryingForTestingPurposes_Hoo
}

func TestDataStore_WithForeignKeyChecksDisabled_DBErrorOnStartingTransaction(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -291,6 +308,8 @@ func TestDataStore_WithForeignKeyChecksDisabled_DBErrorOnStartingTransaction(t *
}

func TestDataStore_WithForeignKeyChecksDisabled_WithTxOptions(t *testing.T) {
testoutput.SuppressIfPasses(t)

var callsCount int
txOptions := &sql.TxOptions{Isolation: sql.LevelReadCommitted}
patch := patchBeginTxWithVerifier(t, &callsCount, txOptions, nil)
Expand All @@ -315,6 +334,8 @@ func TestDataStore_WithForeignKeyChecksDisabled_WithTxOptions(t *testing.T) {
}

func TestDataStore_WithForeignKeyChecksDisabled_DBErrorOnCommittingTransaction(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -337,6 +358,8 @@ func TestDataStore_WithForeignKeyChecksDisabled_DBErrorOnCommittingTransaction(t
}

func TestDataStore_WithForeignKeyChecksDisabled_DBErrorInsideTransaction(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -357,6 +380,8 @@ func TestDataStore_WithForeignKeyChecksDisabled_DBErrorInsideTransaction(t *test
}

func TestDataStore_WithForeignKeyChecksDisabled_DBErrorWithoutTransaction(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -379,6 +404,8 @@ func TestDataStore_WithForeignKeyChecksDisabled_DBErrorWithoutTransaction(t *tes
}

func TestDataStore_WithNamedLock(t *testing.T) {
testoutput.SuppressIfPasses(t)

lockName := "some lock name"
timeout := 1234 * time.Millisecond
expectedTimeout := int(timeout.Round(time.Second).Seconds())
Expand Down Expand Up @@ -417,6 +444,8 @@ func assertNamedLockMethod(t *testing.T, expectedLockName string, expectedTimeou
}

func TestDataStore_RetryOnDuplicatePrimaryKeyError(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, dbMock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -438,6 +467,8 @@ func TestDataStore_RetryOnDuplicatePrimaryKeyError(t *testing.T) {
}

func TestDataStore_RetryOnDuplicateKeyError(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, dbMock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -460,6 +491,8 @@ func TestDataStore_RetryOnDuplicateKeyError(t *testing.T) {
}

func TestDataStore_InsertMap(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -475,6 +508,8 @@ func TestDataStore_InsertMap(t *testing.T) {
}

func TestDataStore_InsertOrUpdateMap(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -492,6 +527,8 @@ func TestDataStore_InsertOrUpdateMap(t *testing.T) {
}

func TestDataStore_InsertOrUpdateMaps(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand All @@ -512,6 +549,8 @@ func TestDataStore_InsertOrUpdateMaps(t *testing.T) {
}

func TestDataStore_WithSharedWriteLock(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down Expand Up @@ -543,6 +582,8 @@ func TestDataStore_WithSharedWriteLock_PanicsWhenNotInTransaction(t *testing.T)
}

func TestDataStore_WithCustomWriteLock(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down Expand Up @@ -592,6 +633,8 @@ func TestDataStore_PropagationsSchedules_MustBeInTransaction(t *testing.T) {
}

func TestProhibitResultsPropagation(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, dbMock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down
4 changes: 4 additions & 0 deletions app/database/db_enums_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/France-ioi/AlgoreaBackend/v2/testhelpers/testoutput"
)

func TestDB_getFromEnumUnderLock_WipesOutAllMapsOnError(t *testing.T) {
testoutput.SuppressIfPasses(t)

db, mock := NewDBMock()
defer func() { _ = db.Close() }()

Expand Down
Loading

0 comments on commit 68f222d

Please sign in to comment.