Skip to content

Commit

Permalink
fix tests on mac arm64 (version 0.10 of resticprofile wasn't built fo…
Browse files Browse the repository at this point in the history
…r darwin_arm64)
  • Loading branch information
creativeprojects committed Jun 25, 2024
1 parent da79215 commit 899c547
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
16 changes: 9 additions & 7 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package selfupdate

import (
"context"
"errors"
"fmt"
stdlog "log"
"os"
Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
})
}
}
Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions mockdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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})
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 899c547

Please sign in to comment.