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"
|
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"
|
|
|
|
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/db/mock"
|
|
|
|
"github.com/Jguer/yay/v11/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 {
|
2020-10-01 13:38:03 +02:00
|
|
|
remote []alpm.IPackage
|
2021-05-13 07:27:24 +02:00
|
|
|
aurdata map[string]*aur.Pkg
|
2020-08-17 02:19:18 +02:00
|
|
|
timeUpdate bool
|
|
|
|
}
|
|
|
|
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{
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{
|
2020-08-17 02:19:18 +02:00
|
|
|
&mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
2020-08-21 02:39:52 +02:00
|
|
|
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
|
|
|
},
|
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{
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{&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
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Time Update",
|
2020-08-17 02:19:18 +02:00
|
|
|
args: args{
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{&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()
|
2020-10-01 14:06:21 +02:00
|
|
|
got := UpAUR(tt.args.remote, tt.args.aurdata, tt.args.timeUpdate)
|
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 {
|
2020-10-01 13:38:03 +02:00
|
|
|
remote []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{},
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{
|
2020-08-17 02:19:18 +02:00
|
|
|
&mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
2020-08-21 02:39:52 +02:00
|
|
|
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
|
|
|
},
|
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
|
|
|
},
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{
|
2020-08-18 01:19:51 +02:00
|
|
|
&mock.Package{PName: "hello", PVersion: "2.0.0"},
|
|
|
|
&mock.Package{PName: "hello2", PVersion: "3.0.0"},
|
2020-08-21 02:39:52 +02:00
|
|
|
&mock.Package{PName: "hello4", PVersion: "4.0.0"},
|
|
|
|
},
|
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{
|
2022-12-18 17:37:15 +01:00
|
|
|
cached: &vcs.Mock{ToUpgradeReturn: []string{}},
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{&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
|
|
|
},
|
2020-10-01 13:38:03 +02:00
|
|
|
remote: []alpm.IPackage{&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-01-03 22:43:56 +01:00
|
|
|
got := UpDevel(context.Background(), 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
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|