27
"plemya-x.ru/alr/internal/db"
28
"plemya-x.ru/alr/internal/types"
29
"plemya-x.ru/alr/pkg/repos"
32
func TestFindPkgs(t *testing.T) {
33
_, err := db.Open(":memory:")
35
t.Fatalf("Expected no error, got %s", err)
40
defer removeCacheDir(t)
42
ctx := context.Background()
44
err = repos.Pull(ctx, []types.Repo{
47
URL: "https://gitea.plemya-x.ru/xpamych/xpamych-alr-repo.git",
51
t.Fatalf("Expected no error, got %s", err)
54
found, notFound, err := repos.FindPkgs([]string{"itd", "nonexistentpackage1", "nonexistentpackage2"})
56
t.Fatalf("Expected no error, got %s", err)
59
if !reflect.DeepEqual(notFound, []string{"nonexistentpackage1", "nonexistentpackage2"}) {
60
t.Errorf("Expected 'nonexistentpackage{1,2} not to be found")
64
t.Errorf("Expected 1 package found, got %d", len(found))
67
itdPkgs, ok := found["itd"]
69
t.Fatalf("Expected 'itd' packages to be found")
73
t.Errorf("Expected two 'itd' packages to be found")
76
for i, pkg := range itdPkgs {
77
if !strings.HasPrefix(pkg.Name, "itd") {
78
t.Errorf("Expected package name of all found packages to start with 'itd', got %s on element %d", pkg.Name, i)
83
func TestFindPkgsEmpty(t *testing.T) {
84
_, err := db.Open(":memory:")
86
t.Fatalf("Expected no error, got %s", err)
91
defer removeCacheDir(t)
93
err = db.InsertPackage(db.Package{
95
Repository: "default",
98
Description: db.NewJSON(map[string]string{
99
"en": "Test package 1",
100
"ru": "Проверочный пакет 1",
102
Provides: db.NewJSON([]string{""}),
105
t.Fatalf("Expected no error, got %s", err)
108
err = db.InsertPackage(db.Package{
110
Repository: "default",
113
Description: db.NewJSON(map[string]string{
114
"en": "Test package 2",
115
"ru": "Проверочный пакет 2",
117
Provides: db.NewJSON([]string{"test"}),
120
t.Fatalf("Expected no error, got %s", err)
123
found, notFound, err := repos.FindPkgs([]string{"test", ""})
125
t.Fatalf("Expected no error, got %s", err)
128
if len(notFound) != 0 {
129
t.Errorf("Expected all packages to be found")
133
t.Errorf("Expected 1 package found, got %d", len(found))
136
testPkgs, ok := found["test"]
138
t.Fatalf("Expected 'test' packages to be found")
141
if len(testPkgs) != 1 {
142
t.Errorf("Expected one 'test' package to be found, got %d", len(testPkgs))
145
if testPkgs[0].Name != "test2" {
146
t.Errorf("Expected 'test2' package, got '%s'", testPkgs[0].Name)