2020-10-01 14:06:21 +02:00
|
|
|
package upgrade
|
2020-08-17 02:19:18 +02:00
|
|
|
|
|
|
|
import (
|
2021-08-12 18:56:23 +02:00
|
|
|
"context"
|
2023-03-08 22:30:54 +01:00
|
|
|
"io"
|
|
|
|
"strings"
|
2020-08-17 02:19:18 +02:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-05-13 07:27:24 +02:00
|
|
|
aur "github.com/Jguer/aur"
|
2020-08-17 02:19:18 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-08-18 01:19:51 +02:00
|
|
|
|
2020-10-01 13:38:03 +02:00
|
|
|
alpm "github.com/Jguer/go-alpm/v2"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db/mock"
|
2023-03-08 22:30:54 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/vcs"
|
2020-08-17 02:19:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_upAUR(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2021-08-11 22:05:47 +02:00
|
|
|
|
2020-08-17 02:19:18 +02:00
|
|
|
type args struct {
|
2023-04-03 18:37:41 +02:00
|
|
|
remote map[string]alpm.IPackage
|
|
|
|
aurdata map[string]*aur.Pkg
|
|
|
|
timeUpdate bool
|
|
|
|
enableDowngrade bool
|
2020-08-17 02:19:18 +02:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2020-10-01 14:06:21 +02:00
|
|
|
want UpSlice
|
2020-08-17 02:19:18 +02:00
|
|
|
}{
|
2020-08-21 02:39:52 +02:00
|
|
|
{
|
|
|
|
name: "No Updates",
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
"local_pkg": &mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
|
|
|
"ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{
|
2020-08-17 02:19:18 +02:00
|
|
|
"hello": {Version: "2.0.0", Name: "hello"},
|
2020-08-21 02:39:52 +02:00
|
|
|
"ignored": {Version: "2.0.0", Name: "ignored"},
|
|
|
|
},
|
2020-08-17 02:19:18 +02:00
|
|
|
timeUpdate: false,
|
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Simple Update",
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.1.0", Name: "hello"}},
|
2020-08-17 02:19:18 +02:00
|
|
|
timeUpdate: false,
|
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"}}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2023-04-03 18:37:41 +02:00
|
|
|
{
|
|
|
|
name: "Downgrade",
|
|
|
|
args: args{
|
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
},
|
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "1.0.0", Name: "hello"}},
|
|
|
|
timeUpdate: false,
|
|
|
|
enableDowngrade: true,
|
|
|
|
},
|
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "1.0.0"}}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Downgrade Disabled",
|
|
|
|
args: args{
|
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
},
|
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "1.0.0", Name: "hello"}},
|
|
|
|
timeUpdate: false,
|
|
|
|
enableDowngrade: false,
|
|
|
|
},
|
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Mixed Updates Downgrades",
|
|
|
|
args: args{
|
|
|
|
enableDowngrade: true,
|
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"up": &mock.Package{PName: "up", PVersion: "2.0.0"},
|
|
|
|
"same": &mock.Package{PName: "same", PVersion: "3.0.0"},
|
|
|
|
"down": &mock.Package{PName: "down", PVersion: "1.1.0"},
|
|
|
|
"ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
|
|
|
},
|
|
|
|
aurdata: map[string]*aur.Pkg{
|
|
|
|
"up": {Version: "2.1.0", Name: "up"},
|
|
|
|
"same": {Version: "3.0.0", Name: "same"},
|
|
|
|
"down": {Version: "1.0.0", Name: "down"},
|
|
|
|
"ignored": {Version: "2.0.0", Name: "ignored"},
|
|
|
|
},
|
|
|
|
timeUpdate: false,
|
|
|
|
},
|
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{
|
|
|
|
{Name: "up", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"},
|
|
|
|
{Name: "down", Repository: "aur", LocalVersion: "1.1.0", RemoteVersion: "1.0.0"},
|
|
|
|
}},
|
|
|
|
},
|
2020-08-21 02:39:52 +02:00
|
|
|
{
|
|
|
|
name: "Time Update",
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0", PBuildDate: time.Now()},
|
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}},
|
2020-08-17 02:19:18 +02:00
|
|
|
timeUpdate: true,
|
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.0.0"}}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2020-08-17 02:19:18 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-17 02:19:18 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2023-01-24 00:03:32 +01:00
|
|
|
|
2023-03-08 22:30:54 +01:00
|
|
|
got := UpAUR(text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
|
2023-04-03 18:37:41 +02:00
|
|
|
tt.args.remote, tt.args.aurdata, tt.args.timeUpdate, tt.args.enableDowngrade)
|
2020-08-17 02:19:18 +02:00
|
|
|
assert.EqualValues(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_upDevel(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-18 01:19:51 +02:00
|
|
|
|
2020-08-17 02:19:18 +02:00
|
|
|
type args struct {
|
2023-01-24 00:03:32 +01:00
|
|
|
remote map[string]alpm.IPackage
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata map[string]*aur.Pkg
|
2022-12-18 17:37:15 +01:00
|
|
|
cached vcs.Store
|
2020-08-17 02:19:18 +02:00
|
|
|
}
|
|
|
|
tests := []struct {
|
2020-08-18 01:19:51 +02:00
|
|
|
name string
|
|
|
|
args args
|
2020-10-01 14:06:21 +02:00
|
|
|
want UpSlice
|
2020-08-18 01:19:51 +02:00
|
|
|
finalLen int
|
2020-08-17 02:19:18 +02:00
|
|
|
}{
|
2020-08-21 02:39:52 +02:00
|
|
|
{
|
|
|
|
name: "No Updates",
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2022-12-18 17:37:15 +01:00
|
|
|
cached: &vcs.Mock{},
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
"local_pkg": &mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
|
|
|
"ignored": &mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{
|
2020-08-17 02:19:18 +02:00
|
|
|
"hello": {Version: "2.0.0", Name: "hello"},
|
2020-08-21 02:39:52 +02:00
|
|
|
"ignored": {Version: "2.0.0", Name: "ignored"},
|
|
|
|
},
|
2020-08-17 02:19:18 +02:00
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"devel"}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Simple Update",
|
2020-08-18 01:19:51 +02:00
|
|
|
finalLen: 3,
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2022-12-18 17:37:15 +01:00
|
|
|
cached: &vcs.Mock{
|
|
|
|
ToUpgradeReturn: []string{"hello", "hello4"},
|
2020-08-18 01:19:51 +02:00
|
|
|
},
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
"hello2": &mock.Package{PName: "hello2", PVersion: "3.0.0"},
|
|
|
|
"hello4": &mock.Package{PName: "hello4", PVersion: "4.0.0"},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{
|
2020-08-18 01:19:51 +02:00
|
|
|
"hello": {Version: "2.0.0", Name: "hello"},
|
|
|
|
"hello2": {Version: "2.0.0", Name: "hello2"},
|
|
|
|
"hello4": {Version: "2.0.0", Name: "hello4"},
|
|
|
|
},
|
|
|
|
},
|
2021-08-02 14:07:33 +02:00
|
|
|
want: UpSlice{
|
|
|
|
Repos: []string{"devel"}, Up: []Upgrade{
|
|
|
|
{
|
|
|
|
Name: "hello",
|
|
|
|
Repository: "devel",
|
|
|
|
LocalVersion: "2.0.0",
|
|
|
|
RemoteVersion: "latest-commit",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hello4",
|
|
|
|
Repository: "devel",
|
|
|
|
LocalVersion: "4.0.0",
|
|
|
|
RemoteVersion: "latest-commit",
|
|
|
|
},
|
|
|
|
},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No update returned",
|
2020-08-18 01:19:51 +02:00
|
|
|
finalLen: 1,
|
|
|
|
args: args{
|
2023-01-24 00:03:32 +01:00
|
|
|
cached: &vcs.Mock{ToUpgradeReturn: []string{}},
|
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
2020-08-17 02:19:18 +02:00
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"devel"}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No update returned - ignored",
|
2020-08-18 01:19:51 +02:00
|
|
|
finalLen: 1,
|
|
|
|
args: args{
|
2022-12-18 17:37:15 +01:00
|
|
|
cached: &vcs.Mock{
|
|
|
|
ToUpgradeReturn: []string{"hello"},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2023-01-24 00:03:32 +01:00
|
|
|
remote: map[string]alpm.IPackage{
|
|
|
|
"hello": &mock.Package{PName: "hello", PVersion: "2.0.0", PShouldIgnore: true},
|
|
|
|
},
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
2020-08-18 01:19:51 +02:00
|
|
|
},
|
2021-04-19 13:43:13 +02:00
|
|
|
want: UpSlice{Repos: []string{"devel"}},
|
2020-08-21 02:39:52 +02:00
|
|
|
},
|
2020-08-17 02:19:18 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-17 02:19:18 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2023-03-08 22:30:54 +01:00
|
|
|
got := UpDevel(context.Background(),
|
|
|
|
text.NewLogger(io.Discard, strings.NewReader(""), false, "test"),
|
|
|
|
tt.args.remote, tt.args.aurdata, tt.args.cached)
|
2021-04-19 13:43:13 +02:00
|
|
|
assert.ElementsMatch(t, tt.want.Up, got.Up)
|
2020-08-17 02:19:18 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|