From 899c547f79930ed9067538c16808bdbc7b93ff04 Mon Sep 17 00:00:00 2001 From: Fred Date: Tue, 25 Jun 2024 15:54:57 +0100 Subject: [PATCH] fix tests on mac arm64 (version 0.10 of resticprofile wasn't built for darwin_arm64) --- detect_test.go | 16 +++++++++------- mockdata_test.go | 24 ++++++++++++------------ update_test.go | 8 ++++---- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/detect_test.go b/detect_test.go index 4eec275..e81bb73 100644 --- a/detect_test.go +++ b/detect_test.go @@ -2,7 +2,6 @@ package selfupdate import ( "context" - "errors" "fmt" stdlog "log" "os" @@ -47,7 +46,7 @@ func TestDetectReleaseWithVersionPrefix(t *testing.T) { require.NoError(t, err) assert.True(t, ok, "Failed to detect latest") require.NotNil(t, r, "No release returned") - if r.LessThan("0.10.0") { + if r.LessThan("0.14.0") { t.Error("Incorrect version:", r.Version()) } if !strings.HasSuffix(r.AssetURL, ".zip") && !strings.HasSuffix(r.AssetURL, ".tar.gz") { @@ -64,7 +63,7 @@ func TestDetectReleaseWithVersionPrefix(t *testing.T) { } func TestDetectVersionExisting(t *testing.T) { - testVersion := "v0.10.0" + testVersion := "v0.14.0" gitHub, _ := NewUpdater(Config{Validator: &ChecksumValidator{UniqueFilename: "checksums.txt"}}) testData := []struct { run bool @@ -91,7 +90,7 @@ func TestDetectVersionExisting(t *testing.T) { } func TestDetectVersionExistingWithNoValidationFile(t *testing.T) { - testVersion := "v0.10.0" + testVersion := "v0.14.0" gitHub, _ := NewUpdater(Config{Validator: &ChecksumValidator{UniqueFilename: "notfound.txt"}}) testData := []struct { run bool @@ -109,8 +108,7 @@ func TestDetectVersionExistingWithNoValidationFile(t *testing.T) { t.Run(testItem.name, func(t *testing.T) { _, _, err := testItem.updater.DetectVersion(context.Background(), testGithubRepository, testVersion) skipRateLimitExceeded(t, err) - require.Error(t, err) - assert.True(t, errors.Is(err, ErrValidationAssetNotFound)) + assert.ErrorIs(t, err, ErrValidationAssetNotFound) }) } } @@ -796,7 +794,7 @@ func TestFindReleaseAndAsset(t *testing.T) { } func TestBuildMultistepValidationChain(t *testing.T) { - testVersion := "v0.10.0" + testVersion := "v0.14.0" source, keyRing := mockPGPSourceRepository(t) checksumValidator := &ChecksumValidator{UniqueFilename: "checksums.txt"} @@ -840,6 +838,10 @@ func TestBuildMultistepValidationChain(t *testing.T) { func newMockUpdater(t *testing.T, config Config) *Updater { t.Helper() + + if config.Source == nil { + config.Source = mockSourceRepository(t) + } updater, err := NewUpdater(config) require.NoError(t, err) return updater diff --git a/mockdata_test.go b/mockdata_test.go index 9c95e7f..1b8ad37 100644 --- a/mockdata_test.go +++ b/mockdata_test.go @@ -57,35 +57,35 @@ func mockSourceRepository(t *testing.T) *MockSource { }, }, &GitHubRelease{ - name: "v0.10.0", - tagName: "v0.10.0", - url: "v0.10.0", + name: "v0.14.0", + tagName: "v0.14.0", + url: "v0.14.0", prerelease: false, publishedAt: time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC), releaseNotes: "latest stable", assets: []SourceAsset{ &GitHubAsset{ id: 4, - name: "resticprofile_0.10.0_linux_amd64.tar.gz", - url: "resticprofile_0.10.0_linux_amd64.tar.gz", + name: "resticprofile_0.14.0_linux_amd64.tar.gz", + url: "resticprofile_0.14.0_linux_amd64.tar.gz", size: len(gzData), }, &GitHubAsset{ id: 5, - name: "resticprofile_0.10.0_darwin_amd64.tar.gz", - url: "resticprofile_0.10.0_darwin_amd64.tar.gz", + name: "resticprofile_0.14.0_darwin_amd64.tar.gz", + url: "resticprofile_0.14.0_darwin_amd64.tar.gz", size: len(gzData), }, &GitHubAsset{ id: 6, - name: "resticprofile_0.10.0_windows_amd64.zip", - url: "resticprofile_0.10.0_windows_amd64.zip", + name: "resticprofile_0.14.0_windows_amd64.zip", + url: "resticprofile_0.14.0_windows_amd64.zip", size: len(zipData), }, &GitHubAsset{ id: 32, - name: "resticprofile_0.10.0_darwin_arm64.tar.gz", - url: "resticprofile_0.10.0_darwin_arm64.tar.gz", + name: "resticprofile_0.14.0_darwin_arm64.tar.gz", + url: "resticprofile_0.14.0_darwin_arm64.tar.gz", size: len(gzData), }, }, @@ -273,7 +273,7 @@ func mockSourceRepository(t *testing.T) *MockSource { name: "checksums.txt", }) files[id] = checksums.Bytes() - t.Logf("file id %d contains checksums:\n%s\n", id, string(files[id])) + // t.Logf("file id %d contains checksums:\n%s\n", id, string(files[id])) } return NewMockSource(releases, files) diff --git a/update_test.go b/update_test.go index e58d028..9b398c5 100644 --- a/update_test.go +++ b/update_test.go @@ -22,7 +22,7 @@ func TestUpdateCommandWithWrongVersion(t *testing.T) { } func TestUpdateCommand(t *testing.T) { - current := "0.10.0" + current := "0.14.0" new := "1.0.0" source := mockSourceRepository(t) updater, err := NewUpdater(Config{Source: source}) @@ -42,7 +42,7 @@ func TestUpdateViaSymlink(t *testing.T) { t.Skip("skipping because creating symlink on windows requires admin privilege") } - current := "0.10.0" + current := "0.14.0" new := "1.0.0" source := mockSourceRepository(t) updater, err := NewUpdater(Config{Source: source}) @@ -91,7 +91,7 @@ func TestUpdateBrokenSymlinks(t *testing.T) { defer os.Remove(xxx) for _, filename := range []string{yyy, xxx} { - _, err := updater.UpdateCommand(context.Background(), filename, "0.10.0", ParseSlug("owner/repo")) + _, err := updater.UpdateCommand(context.Background(), filename, "0.14.0", ParseSlug("owner/repo")) assert.Error(t, err) assert.Contains(t, err.Error(), "failed to resolve symlink") } @@ -416,7 +416,7 @@ func TestUpdateToSuccess(t *testing.T) { } func TestUpdateToWithMultistepValidationChain(t *testing.T) { - testVersion := "v0.10.0" + testVersion := "v0.14.0" source, keyRing := mockPGPSourceRepository(t) updater, _ := NewUpdater(Config{ Source: source,