Skip to content

Commit

Permalink
PMM-7 Fix compatibility service tests (#2608)
Browse files Browse the repository at this point in the history
* PMM-7 Fix compatibility service tests

* PMM-7 fix postgresql version test.

---------

Co-authored-by: Nurlan Moldomurov <[email protected]>
  • Loading branch information
artemgavrilov and BupycHuk authored Nov 9, 2023
1 parent 38a221c commit 1e813cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions managed/models/postgresql_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import (

func TestGetPostgreSQLVersion(t *testing.T) {
t.Parallel()
sqlDB, mock, err := sqlmock.New()
require.NoError(t, err)
t.Cleanup(func() { sqlDB.Close() }) //nolint:errcheck

q := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(t.Logf)).WithTag("pmm-agent:postgresqlversion")
ctx := context.Background()

testCases := []struct {
name string
Expand Down Expand Up @@ -79,8 +73,16 @@ func TestGetPostgreSQLVersion(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

sqlDB, mock, err := sqlmock.New()
require.NoError(t, err)
t.Cleanup(func() { sqlDB.Close() }) //nolint:errcheck

q := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(t.Logf)).WithTag("pmm-agent:postgresqlversion")
ctx := context.Background()

for _, version := range tc.mockedData {
mock.ExpectQuery("SELECT").
mock.ExpectQuery("SELECT version()").
WillReturnRows(sqlmock.NewRows(column).AddRow(version))
}

Expand Down
6 changes: 3 additions & 3 deletions managed/services/backup/compatibility_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (

func TestCheckCompatibility(t *testing.T) {
t.Parallel()
mockVersioner := mockVersioner{}
cSvc := NewCompatibilityService(nil, &mockVersioner)

agentModel := models.Agent{AgentID: "test_agent_id"}

Expand Down Expand Up @@ -194,7 +192,9 @@ func TestCheckCompatibility(t *testing.T) {
sw = mongoSoftware
default: // just to satisfy linters
}
mockVersioner := mockVersioner{}
mockVersioner.On("GetVersions", agentModel.AgentID, sw).Return(tc.versions, nil).Once()
cSvc := NewCompatibilityService(nil, &mockVersioner)
dbVersion, err := cSvc.checkCompatibility(&models.Service{ServiceType: tc.serviceType}, &agentModel)
if tc.expectedError != nil {
assert.ErrorIs(t, err, tc.expectedError)
Expand All @@ -203,9 +203,9 @@ func TestCheckCompatibility(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tc.versions[0].Version, dbVersion)
}
mock.AssertExpectationsForObjects(t, &mockVersioner)
})
}
mock.AssertExpectationsForObjects(t, &mockVersioner)
}

func TestFindCompatibleServiceIDs(t *testing.T) {
Expand Down

0 comments on commit 1e813cf

Please sign in to comment.