2020-08-21 02:37:03 +02:00
|
|
|
package vcs
|
|
|
|
|
|
|
|
import (
|
2021-08-12 18:56:23 +02:00
|
|
|
"context"
|
2020-08-22 00:39:26 +02:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2020-08-21 02:37:03 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-08-22 00:39:26 +02:00
|
|
|
gosrc "github.com/Morganamilo/go-srcinfo"
|
|
|
|
"github.com/bradleyjkemp/cupaloy"
|
2020-08-21 02:37:03 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-08-05 18:56:28 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-08-22 00:39:26 +02:00
|
|
|
|
2021-09-08 22:28:08 +02:00
|
|
|
"github.com/Jguer/yay/v11/pkg/settings/exe"
|
2020-08-21 02:37:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParsing(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-21 02:37:03 +02:00
|
|
|
type source struct {
|
|
|
|
URL string
|
|
|
|
Branch string
|
|
|
|
Protocols []string
|
|
|
|
}
|
|
|
|
|
|
|
|
urls := []string{
|
|
|
|
"git+https://github.com/neovim/neovim.git",
|
|
|
|
"git://github.com/jguer/yay.git#branch=master",
|
|
|
|
"git://github.com/davidgiven/ack",
|
|
|
|
"git://github.com/jguer/yay.git#tag=v3.440",
|
|
|
|
"git://github.com/jguer/yay.git#commit=e5470c88c6e2f9e0f97deb4728659ffa70ef5d0c",
|
|
|
|
"a+b+c+d+e+f://github.com/jguer/yay.git#branch=foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
sources := []source{
|
|
|
|
{"github.com/neovim/neovim.git", "HEAD", []string{"https"}},
|
|
|
|
{"github.com/jguer/yay.git", "master", []string{"git"}},
|
|
|
|
{"github.com/davidgiven/ack", "HEAD", []string{"git"}},
|
|
|
|
{"", "", nil},
|
|
|
|
{"", "", nil},
|
|
|
|
{"", "", nil},
|
|
|
|
}
|
|
|
|
|
|
|
|
for n, url := range urls {
|
|
|
|
url, branch, protocols := parseSource(url)
|
|
|
|
compare := sources[n]
|
|
|
|
|
|
|
|
assert.Equal(t, compare.URL, url)
|
|
|
|
assert.Equal(t, compare.Branch, branch)
|
|
|
|
assert.Equal(t, compare.Protocols, protocols)
|
|
|
|
}
|
|
|
|
}
|
2020-08-22 00:39:26 +02:00
|
|
|
|
|
|
|
func TestNewInfoStore(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
type args struct {
|
|
|
|
filePath string
|
|
|
|
cmdBuilder *exe.CmdBuilder
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "normal",
|
2020-08-22 01:24:52 +02:00
|
|
|
args: args{
|
|
|
|
"/tmp/a.json",
|
2021-08-08 20:22:39 +02:00
|
|
|
&exe.CmdBuilder{GitBin: "git", GitFlags: []string{"--a", "--b"}, Runner: &exe.OSRunner{}},
|
2020-08-22 01:24:52 +02:00
|
|
|
},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-22 00:39:26 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2021-08-08 20:22:39 +02:00
|
|
|
got := NewInfoStore(tt.args.filePath, tt.args.cmdBuilder)
|
2020-08-22 00:39:26 +02:00
|
|
|
assert.NotNil(t, got)
|
2021-08-08 09:28:53 +02:00
|
|
|
assert.Equal(t, []string{"--a", "--b"}, got.CmdBuilder.(*exe.CmdBuilder).GitFlags)
|
2020-08-22 00:39:26 +02:00
|
|
|
assert.Equal(t, tt.args.cmdBuilder, got.CmdBuilder)
|
|
|
|
assert.Equal(t, "/tmp/a.json", got.FilePath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MockRunner struct {
|
|
|
|
Returned []string
|
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *MockRunner) Show(cmd *exec.Cmd) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-12 18:56:23 +02:00
|
|
|
func (r *MockRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
|
2020-08-22 00:39:26 +02:00
|
|
|
stdout = r.Returned[r.Index]
|
|
|
|
if r.Returned[0] == "error" {
|
|
|
|
err = errors.New("possible error")
|
|
|
|
}
|
|
|
|
return stdout, stderr, err
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:37:15 +01:00
|
|
|
func TestInfoStoreToUpgrade(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
type fields struct {
|
|
|
|
CmdBuilder *exe.CmdBuilder
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
infos OriginInfoByURL
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "simple-has_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []string{"yay"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "double-has_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
},
|
|
|
|
"github.com/Jguer/a.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
|
|
|
Returned: []string{
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD",
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD",
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []string{"yay"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
|
|
|
Returned: []string{"991c5b4146fd27f4aacf4e3111258a848934aaa1 HEAD"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no_split",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-error",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{
|
|
|
|
GitBin: "git", GitFlags: []string{""},
|
|
|
|
Runner: &MockRunner{
|
|
|
|
Returned: []string{"error"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no protocol",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
tt := tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
v := &InfoStore{
|
|
|
|
CmdBuilder: tt.fields.CmdBuilder,
|
|
|
|
OriginsByPackage: map[string]OriginInfoByURL{
|
|
|
|
"yay": tt.args.infos,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
got := v.ToUpgrade(context.Background())
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-22 00:39:26 +02:00
|
|
|
func TestInfoStore_NeedsUpdate(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
type fields struct {
|
|
|
|
CmdBuilder *exe.CmdBuilder
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
infos OriginInfoByURL
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "simple-has_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
2020-08-22 00:39:26 +02:00
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD"},
|
2021-08-08 20:22:39 +02:00
|
|
|
}},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "double-has_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
},
|
|
|
|
"github.com/Jguer/a.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
2020-08-22 00:39:26 +02:00
|
|
|
Returned: []string{
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD",
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD",
|
|
|
|
},
|
2021-08-08 20:22:39 +02:00
|
|
|
}},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no_update",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
2020-08-22 00:39:26 +02:00
|
|
|
Returned: []string{"991c5b4146fd27f4aacf4e3111258a848934aaa1 HEAD"},
|
2021-08-08 20:22:39 +02:00
|
|
|
}},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no_split",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
2020-08-22 00:39:26 +02:00
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
2021-08-08 20:22:39 +02:00
|
|
|
}},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-error",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{"https"},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{
|
|
|
|
GitBin: "git", GitFlags: []string{""},
|
|
|
|
Runner: &MockRunner{
|
|
|
|
Returned: []string{"error"},
|
|
|
|
},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple-no protocol",
|
|
|
|
args: args{infos: OriginInfoByURL{
|
|
|
|
"github.com/Jguer/z.git": OriginInfo{
|
|
|
|
Protocols: []string{},
|
|
|
|
Branch: "0",
|
|
|
|
SHA: "991c5b4146fd27f4aacf4e3111258a848934aaa1",
|
|
|
|
},
|
|
|
|
}}, fields: fields{
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{GitBin: "git", GitFlags: []string{""}, Runner: &MockRunner{
|
2020-08-22 00:39:26 +02:00
|
|
|
Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
2021-08-08 20:22:39 +02:00
|
|
|
}},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-22 00:39:26 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
v := &InfoStore{
|
|
|
|
CmdBuilder: tt.fields.CmdBuilder,
|
|
|
|
}
|
2023-01-03 22:43:56 +01:00
|
|
|
got := v.needsUpdate(context.Background(), tt.args.infos)
|
2020-08-22 00:39:26 +02:00
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfoStore_Update(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
type fields struct {
|
|
|
|
OriginsByPackage map[string]OriginInfoByURL
|
|
|
|
CmdBuilder *exe.CmdBuilder
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
pkgName string
|
|
|
|
sources []gosrc.ArchString
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
}{
|
2020-10-01 13:38:03 +02:00
|
|
|
{
|
|
|
|
name: "simple",
|
|
|
|
args: args{
|
|
|
|
pkgName: "hello",
|
|
|
|
sources: []gosrc.ArchString{{Value: "git://github.com/jguer/yay.git#branch=master"}},
|
|
|
|
},
|
2020-08-22 00:39:26 +02:00
|
|
|
fields: fields{
|
|
|
|
OriginsByPackage: make(map[string]OriginInfoByURL),
|
2021-08-08 20:22:39 +02:00
|
|
|
CmdBuilder: &exe.CmdBuilder{
|
|
|
|
GitBin: "git", GitFlags: []string{""},
|
|
|
|
Runner: &MockRunner{Returned: []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa HEAD"}},
|
|
|
|
},
|
2020-08-22 00:39:26 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-05 18:56:28 +02:00
|
|
|
file, err := os.CreateTemp("/tmp", "yay-infostore-*-test")
|
|
|
|
filePath := file.Name()
|
|
|
|
require.NoError(t, err)
|
2020-08-22 00:39:26 +02:00
|
|
|
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-22 00:39:26 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
v := &InfoStore{
|
|
|
|
OriginsByPackage: tt.fields.OriginsByPackage,
|
2022-08-05 18:56:28 +02:00
|
|
|
FilePath: filePath,
|
2020-08-22 00:39:26 +02:00
|
|
|
CmdBuilder: tt.fields.CmdBuilder,
|
|
|
|
}
|
2022-12-18 17:37:15 +01:00
|
|
|
|
2023-01-03 22:43:56 +01:00
|
|
|
v.Update(context.Background(), tt.args.pkgName, tt.args.sources)
|
2020-08-22 00:39:26 +02:00
|
|
|
assert.Len(t, tt.fields.OriginsByPackage, 1)
|
|
|
|
|
|
|
|
marshalledinfo, err := json.MarshalIndent(tt.fields.OriginsByPackage, "", "\t")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
cupaloy.SnapshotT(t, marshalledinfo)
|
|
|
|
|
|
|
|
v.Load()
|
|
|
|
fmt.Println(v.OriginsByPackage)
|
|
|
|
assert.Len(t, tt.fields.OriginsByPackage, 1)
|
|
|
|
|
|
|
|
marshalledinfo, err = json.MarshalIndent(tt.fields.OriginsByPackage, "", "\t")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
cupaloy.SnapshotT(t, marshalledinfo)
|
|
|
|
})
|
|
|
|
}
|
2022-08-05 18:56:28 +02:00
|
|
|
|
|
|
|
require.NoError(t, os.Remove(filePath))
|
2020-08-22 00:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfoStore_Remove(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
type fields struct {
|
|
|
|
OriginsByPackage map[string]OriginInfoByURL
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
pkgs []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
}{
|
2020-10-01 13:38:03 +02:00
|
|
|
{
|
|
|
|
name: "simple",
|
2020-08-22 00:39:26 +02:00
|
|
|
args: args{pkgs: []string{"a", "c"}},
|
|
|
|
fields: fields{
|
|
|
|
OriginsByPackage: map[string]OriginInfoByURL{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
"d": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-05 18:56:28 +02:00
|
|
|
file, err := os.CreateTemp("/tmp", "yay-vcs-*-test")
|
|
|
|
filePath := file.Name()
|
|
|
|
require.NoError(t, err)
|
2020-08-22 00:39:26 +02:00
|
|
|
|
|
|
|
for _, tt := range tests {
|
2021-08-11 20:13:28 +02:00
|
|
|
tt := tt
|
2020-08-22 00:39:26 +02:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-08-11 20:13:28 +02:00
|
|
|
t.Parallel()
|
2020-08-22 00:39:26 +02:00
|
|
|
v := &InfoStore{
|
|
|
|
OriginsByPackage: tt.fields.OriginsByPackage,
|
2022-08-05 18:56:28 +02:00
|
|
|
FilePath: filePath,
|
2020-08-22 00:39:26 +02:00
|
|
|
}
|
|
|
|
v.RemovePackage(tt.args.pkgs)
|
|
|
|
assert.Len(t, tt.fields.OriginsByPackage, 2)
|
|
|
|
})
|
|
|
|
}
|
2022-08-05 18:56:28 +02:00
|
|
|
|
|
|
|
require.NoError(t, os.Remove(filePath))
|
2020-08-22 00:39:26 +02:00
|
|
|
}
|