chore(migration): default to "" as sortBy to keep existing behavior (#2768)
* bump builtin version * add sortby migration to keep current user behavior
This commit is contained in:
5 files changed
+136
-3
No files matched your search
@@ -10,7 +10,7 @@ GO ?= go
|
||||
PKGNAME := yay
|
||||
PREFIX := /usr/local
|
||||
|
||||
MAJORVERSION := 12
|
||||
MAJORVERSION := 13
|
||||
MINORVERSION := 0
|
||||
PATCHVERSION := 0
|
||||
VERSION ?= ${MAJORVERSION}.${MINORVERSION}.${PATCHVERSION}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
yayVersion = "12.5.3" // To be set by compiler.
|
||||
yayVersion = "13.0.0" // To be set by compiler.
|
||||
localePath = "/usr/share/locale" // To be set by compiler.
|
||||
)
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ func DefaultConfig(version string) *Configuration {
|
||||
BottomUp: true,
|
||||
CompletionInterval: 7,
|
||||
MaxConcurrentDownloads: 1,
|
||||
SortBy: "votes",
|
||||
SortBy: "",
|
||||
SearchBy: "name-desc",
|
||||
SudoLoop: false,
|
||||
GitBin: "git",
|
||||
|
||||
@@ -39,9 +39,30 @@ func (migration *configProviderMigration) TargetVersion() string {
|
||||
return "11.2.1"
|
||||
}
|
||||
|
||||
type configSortByMigration struct{}
|
||||
|
||||
func (migration *configSortByMigration) String() string {
|
||||
return gotext.Get("Reset 'sortby' setting to default")
|
||||
}
|
||||
|
||||
func (migration *configSortByMigration) Do(config *Configuration) bool {
|
||||
if config.SortBy != "" {
|
||||
config.SortBy = ""
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (migration *configSortByMigration) TargetVersion() string {
|
||||
return "13.0.0"
|
||||
}
|
||||
|
||||
func DefaultMigrations() []configMigration {
|
||||
return []configMigration{
|
||||
&configProviderMigration{},
|
||||
&configSortByMigration{},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -161,3 +161,115 @@ func TestProvidesMigration(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortByMigrationDo(t *testing.T) {
|
||||
migration := &configSortByMigration{}
|
||||
config := Configuration{
|
||||
SortBy: "name",
|
||||
}
|
||||
|
||||
assert.True(t, migration.Do(&config))
|
||||
|
||||
falseConfig := Configuration{SortBy: ""}
|
||||
|
||||
assert.False(t, migration.Do(&falseConfig))
|
||||
}
|
||||
|
||||
func TestSortByMigration(t *testing.T) {
|
||||
t.Parallel()
|
||||
type testCase struct {
|
||||
desc string
|
||||
testConfig *Configuration
|
||||
newVersion string
|
||||
wantSave bool
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
desc: "to upgrade",
|
||||
testConfig: &Configuration{
|
||||
Version: "12.9.0",
|
||||
SortBy: "name",
|
||||
},
|
||||
newVersion: "13.0.0",
|
||||
wantSave: true,
|
||||
},
|
||||
{
|
||||
desc: "to upgrade-git",
|
||||
testConfig: &Configuration{
|
||||
Version: "12.9.0.r7.g6f60892",
|
||||
SortBy: "votes",
|
||||
},
|
||||
newVersion: "13.0.0",
|
||||
wantSave: true,
|
||||
},
|
||||
{
|
||||
desc: "to not upgrade",
|
||||
testConfig: &Configuration{
|
||||
Version: "12.9.0",
|
||||
SortBy: "",
|
||||
},
|
||||
newVersion: "13.0.0",
|
||||
wantSave: false,
|
||||
},
|
||||
{
|
||||
desc: "to not upgrade - target version",
|
||||
testConfig: &Configuration{
|
||||
Version: "13.0.0",
|
||||
SortBy: "name",
|
||||
},
|
||||
newVersion: "13.0.0",
|
||||
wantSave: false,
|
||||
},
|
||||
{
|
||||
desc: "to not upgrade - new version",
|
||||
testConfig: &Configuration{
|
||||
Version: "13.1.0",
|
||||
SortBy: "name",
|
||||
},
|
||||
newVersion: "13.1.0",
|
||||
wantSave: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Create temporary file for config
|
||||
configFile, err := os.CreateTemp("/tmp", "yay-*-config.json")
|
||||
require.NoError(t, err)
|
||||
|
||||
testFilePath := configFile.Name()
|
||||
defer os.Remove(testFilePath)
|
||||
// Create config with configVersion and sortby
|
||||
tcConfig := Configuration{
|
||||
Version: tc.testConfig.Version,
|
||||
SortBy: tc.testConfig.SortBy,
|
||||
// Create runtime with runtimeVersion
|
||||
}
|
||||
|
||||
// Run Migration
|
||||
err = tcConfig.RunMigrations(newTestLogger(),
|
||||
[]configMigration{&configSortByMigration{}},
|
||||
testFilePath, tc.newVersion)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check file contents if wantSave otherwise check file empty
|
||||
cfile, err := os.Open(testFilePath)
|
||||
require.NoError(t, err)
|
||||
defer cfile.Close()
|
||||
|
||||
decoder := json.NewDecoder(cfile)
|
||||
newConfig := Configuration{}
|
||||
err = decoder.Decode(&newConfig)
|
||||
if tc.wantSave {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.newVersion, newConfig.Version)
|
||||
assert.Equal(t, "", newConfig.SortBy)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
assert.Empty(t, newConfig.Version)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user