From b6b01b6c67e4dee494ffdd6d3ba569fbc820f8da Mon Sep 17 00:00:00 2001 From: Michael Okoko <10512379+idoqo@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:13:35 +0100 Subject: [PATCH] PMM-7 fix updates test (#3050) * Fix PMM version tests * update test condition to support v3 --- api-tests/server/updates_test.go | 24 +++++++++++------------- managed/services/server/updater_test.go | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/api-tests/server/updates_test.go b/api-tests/server/updates_test.go index 4285182f17..f9f0d59d56 100644 --- a/api-tests/server/updates_test.go +++ b/api-tests/server/updates_test.go @@ -55,8 +55,8 @@ func TestCheckUpdates(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, res.Payload.Installed) - assert.True(t, strings.HasPrefix(res.Payload.Installed.Version, "2."), - "installed.version = %q should have '2.' prefix", res.Payload.Installed.Version) + assert.True(t, strings.HasPrefix(res.Payload.Installed.Version, "2.") || strings.HasPrefix(res.Payload.Installed.Version, "3."), + "installed.version = %q should have '2.' or '3.' prefix", res.Payload.Installed.Version) assert.NotEmpty(t, res.Payload.Installed.FullVersion) require.NotEmpty(t, res.Payload.Installed.Timestamp) ts := time.Time(res.Payload.Installed.Timestamp) @@ -65,23 +65,21 @@ func TestCheckUpdates(t *testing.T) { assert.Zero(t, min, "installed.timestamp should contain only date") require.NotEmpty(t, res.Payload.Latest) - assert.True(t, strings.HasPrefix(res.Payload.Latest.Version, "2."), - "latest.version = %q should have '2.' prefix", res.Payload.Latest.Version) - require.NotEmpty(t, res.Payload.Latest.Timestamp) - ts = time.Time(res.Payload.Latest.Timestamp) - hour, min, _ = ts.Clock() - assert.Zero(t, hour, "latest.timestamp should contain only date") - assert.Zero(t, min, "latest.timestamp should contain only date") + assert.True(t, strings.HasPrefix(res.Payload.Installed.Version, "2.") || strings.HasPrefix(res.Payload.Installed.Version, "3."), + "installed.version = %q should have '2.' or '3.' prefix", res.Payload.Installed.Version) + assert.NotEmpty(t, res.Payload.Installed.FullVersion) if res.Payload.UpdateAvailable { assert.NotEmpty(t, res.Payload.Latest.Tag) + require.NotEmpty(t, res.Payload.Latest.Timestamp) + ts = time.Time(res.Payload.Latest.Timestamp) + hour, min, _ = ts.Clock() + assert.Zero(t, hour, "latest.timestamp should contain only date") + assert.Zero(t, min, "latest.timestamp should contain only date") + assert.NotEqual(t, res.Payload.Installed.FullVersion, res.Payload.Latest.Version) assert.NotEqual(t, res.Payload.Installed.Timestamp, res.Payload.Latest.Timestamp) assert.True(t, strings.HasPrefix(res.Payload.LatestNewsURL, "https://per.co.na/pmm/2."), "latest_news_url = %q", res.Payload.LatestNewsURL) - } else { - assert.Equal(t, res.Payload.Installed.Timestamp, res.Payload.Latest.Timestamp) - assert.Empty(t, res.Payload.Installed.FullVersion, res.Payload.Latest.Version) - assert.Empty(t, res.Payload.LatestNewsURL, "latest_news_url should be empty") } assert.NotEmpty(t, res.Payload.LastCheck) diff --git a/managed/services/server/updater_test.go b/managed/services/server/updater_test.go index 68bb6e69f4..3f033bfbb9 100644 --- a/managed/services/server/updater_test.go +++ b/managed/services/server/updater_test.go @@ -246,13 +246,13 @@ func TestUpdater(t *testing.T) { }) t.Run("TestLatest", func(t *testing.T) { - // Used PMM 2, because PMM 3 is not released yet. version.Version = "2.41.0" u := NewUpdater(watchtowerURL, gRPCMessageMaxSize) latest, err := u.latest(context.Background()) require.NoError(t, err) assert.NotNil(t, latest) - assert.True(t, strings.HasPrefix(latest.Version.String(), "2.41."), "latest version of PMM 2 should have prefix 2.41.") + assert.True(t, strings.HasPrefix(latest.Version.String(), "2.") || strings.HasPrefix(latest.Version.String(), "3."), + "latest version of PMM 2 should have prefix 2.") }) t.Run("TestParseFile", func(t *testing.T) {