-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update parser to match the v4 format (#438)
Co-authored-by: Elsie <hwengerstickel@protonmail.com>
- Loading branch information
Showing
8 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/fixtures/test-programs/packages/sample-valid-deb/sample-valid-deb.pacscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name="sample-valid-deb" | ||
pkgname="sample-valid" | ||
gives="sample-valid" | ||
repology=("project: sample-valid") | ||
pkgver="1.0.0" | ||
url="https://example.com" | ||
pkgdesc="Sample description" | ||
hash="10101010" | ||
arch=('amd64') | ||
makedepends=("go" "gcc") | ||
optdepends=("opt1" "opt2") | ||
pacdeps=("pacdep1" "pacdep2") | ||
depends=("dep1" "dep2") | ||
ppa=("ppa1" "ppa2") | ||
patch=("patch1" "patch2") | ||
provides=("provides1" "provides2") | ||
incompatible=("incompatible1" "incompatible2") | ||
maintainer="pacstall <test@pacstall.dev>" | ||
breaks=("breaks1" "breaks2") | ||
replace=("replaces1" "replaces2") |
23 changes: 23 additions & 0 deletions
23
...ms/packages/sample-valid-with-pkgver-func-deb/sample-valid-with-pkgver-func-deb.pacscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name="sample-valid-deb" | ||
pkgname="sample-valid" | ||
gives="sample-valid" | ||
repology=("project: sample-valid") | ||
url="https://example.com" | ||
pkgdesc="Sample description" | ||
hash="10101010" | ||
arch=('amd64') | ||
makedepends=("go" "gcc") | ||
optdepends=("opt1" "opt2") | ||
pacdeps=("pacdep1" "pacdep2") | ||
depends=("dep1" "dep2") | ||
ppa=("ppa1" "ppa2") | ||
patch=("patch1" "patch2") | ||
provides=("provides1" "provides2") | ||
incompatible=("incompatible1" "incompatible2") | ||
maintainer="pacstall <test@pacstall.dev>" | ||
breaks=("breaks1" "breaks2") | ||
replace=("replaces1" "replaces2") | ||
|
||
pkgver() { | ||
echo "1.2.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package parser_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"pacstall.dev/webserver/types/pac" | ||
"pacstall.dev/webserver/types/pac/parser" | ||
"pacstall.dev/webserver/types/pac/parser/pacsh" | ||
) | ||
|
||
var FIXTURES_DIR = func() string { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return path.Join(dir, "../../../fixtures") | ||
}() | ||
|
||
var TEST_PROGRAMS_DIR = path.Join(FIXTURES_DIR, "test-programs") | ||
|
||
func assertEquals(t *testing.T, what string, expected interface{}, actual interface{}) { | ||
if actual != expected { | ||
t.Errorf("expected %v '%v', got '%v'", what, expected, actual) | ||
} | ||
} | ||
|
||
func assertArrayEquals(t *testing.T, what string, expected []string, actual []string) { | ||
if len(actual) != len(expected) { | ||
t.Errorf("expected %v '%v', got '%v'", what, expected, actual) | ||
} | ||
|
||
for idx := range expected { | ||
if expected[idx] != actual[idx] { | ||
t.Errorf("expected %v '%v', got '%v'", what, expected, actual) | ||
} | ||
} | ||
} | ||
|
||
func assertPacscriptEquals(t *testing.T, expected pac.Script, actual pac.Script) { | ||
assertEquals(t, "name", expected.Name, actual.Name) | ||
assertEquals(t, "package name", expected.PackageName, actual.PackageName) | ||
assertEquals(t, "maintainer", expected.Maintainer, actual.Maintainer) | ||
assertEquals(t, "description", expected.Description, actual.Description) | ||
assertEquals(t, "gives", expected.Gives, actual.Gives) | ||
assertEquals(t, "hash", *expected.Hash, *actual.Hash) | ||
assertEquals(t, "version", expected.Version, actual.Version) | ||
assertArrayEquals(t, "breaks", expected.Breaks, actual.Breaks) | ||
assertArrayEquals(t, "replace", expected.Replace, actual.Replace) | ||
assertEquals(t, "pretty name", expected.PrettyName, actual.PrettyName) | ||
assertEquals(t, "url", expected.URL, actual.URL) | ||
assertArrayEquals(t, "runtime dependencies", expected.RuntimeDependencies, actual.RuntimeDependencies) | ||
assertArrayEquals(t, "build dependencies", expected.BuildDependencies, actual.BuildDependencies) | ||
assertArrayEquals(t, "optional dependencies", expected.OptionalDependencies, actual.OptionalDependencies) | ||
assertArrayEquals(t, "pacstall dependencies", expected.PacstallDependencies, actual.PacstallDependencies) | ||
assertArrayEquals(t, "ppa", expected.PPA, actual.PPA) | ||
assertArrayEquals(t, "patch", expected.Patch, actual.Patch) | ||
assertArrayEquals(t, "required by", expected.RequiredBy, actual.RequiredBy) | ||
assertArrayEquals(t, "repology", expected.Repology, actual.Repology) | ||
assertEquals(t, "update status", expected.UpdateStatus, actual.UpdateStatus) | ||
} | ||
|
||
func Test_ParsePacscriptFile_Valid(t *testing.T) { | ||
if pacsh.CreateTempDirectory("./tmp") != nil { | ||
t.Errorf("failed to create temp directory") | ||
return | ||
} | ||
|
||
actual, err := parser.ParsePacscriptFile(TEST_PROGRAMS_DIR, "sample-valid-deb") | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
return | ||
} | ||
|
||
hash := "10101010" | ||
expected := pac.Script{ | ||
Name: "sample-valid-deb", | ||
PackageName: "sample-valid", | ||
Maintainer: "pacstall <test@pacstall.dev>", | ||
Description: "Sample description", | ||
Gives: "sample-valid", | ||
Hash: &hash, | ||
Version: "1.0.0", | ||
Breaks: []string{"breaks1", "breaks2"}, | ||
Replace: []string{"replaces1", "replaces2"}, | ||
PrettyName: "Sample Valid", | ||
URL: "https://example.com", | ||
RuntimeDependencies: []string{"dep1", "dep2"}, | ||
BuildDependencies: []string{"go", "gcc"}, | ||
OptionalDependencies: []string{"opt1", "opt2"}, | ||
PacstallDependencies: []string{"pacdep1", "pacdep2"}, | ||
PPA: []string{"ppa1", "ppa2"}, | ||
Patch: []string{"patch1", "patch2"}, | ||
RequiredBy: []string{}, | ||
Repology: []string{"project: sample-valid"}, | ||
UpdateStatus: pac.UpdateStatus.Unknown, | ||
} | ||
|
||
assertPacscriptEquals(t, expected, actual) | ||
} | ||
|
||
func Test_ParsePacscriptFile_WithPkgverFunc_Valid(t *testing.T) { | ||
if pacsh.CreateTempDirectory("./tmp") != nil { | ||
t.Errorf("failed to create temp directory") | ||
return | ||
} | ||
|
||
actual, err := parser.ParsePacscriptFile(TEST_PROGRAMS_DIR, "sample-valid-with-pkgver-func-deb") | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
return | ||
} | ||
|
||
hash := "10101010" | ||
expected := pac.Script{ | ||
Name: "sample-valid-deb", | ||
PackageName: "sample-valid", | ||
Maintainer: "pacstall <test@pacstall.dev>", | ||
Description: "Sample description", | ||
Gives: "sample-valid", | ||
Hash: &hash, | ||
Version: "1.2.3", | ||
Breaks: []string{"breaks1", "breaks2"}, | ||
Replace: []string{"replaces1", "replaces2"}, | ||
PrettyName: "Sample Valid", | ||
URL: "https://example.com", | ||
RuntimeDependencies: []string{"dep1", "dep2"}, | ||
BuildDependencies: []string{"go", "gcc"}, | ||
OptionalDependencies: []string{"opt1", "opt2"}, | ||
PacstallDependencies: []string{"pacdep1", "pacdep2"}, | ||
PPA: []string{"ppa1", "ppa2"}, | ||
Patch: []string{"patch1", "patch2"}, | ||
RequiredBy: []string{}, | ||
Repology: []string{"project: sample-valid"}, | ||
UpdateStatus: pac.UpdateStatus.Unknown, | ||
} | ||
|
||
assertPacscriptEquals(t, expected, actual) | ||
} |