Skip to content

Commit

Permalink
Account for colons in version value.
Browse files Browse the repository at this point in the history
  • Loading branch information
awalsh128 committed Nov 27, 2023
1 parent 19a0253 commit 7c7bced
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apt_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func getPackages(names []string) AptPackages {
pkg := AptPackage{}
for _, line := range strings.Split(paragraph, "\n") {
if strings.HasPrefix(line, "Package: ") {
pkg.Name = strings.TrimSpace(strings.Split(line, ":")[1])
pkg.Name = strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
} else if strings.HasPrefix(line, "Version: ") {
pkg.Version = strings.TrimSpace(strings.Split(line, ":")[1])
} else if strings.HasPrefix(line, "N: Unable to locate package ") || strings.HasPrefix(line, "E: ") {
pkg.Version = strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
} else if strings.HasPrefix(line, "N: ") || strings.HasPrefix(line, "E: ") {
if !contains(errorMessages, line) {
errorMessages = append(errorMessages, line)
}
Expand Down
15 changes: 11 additions & 4 deletions apt_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ func (r *RunResult) expectSuccessfulOut(expected string) {
if r.Stderr != "" {
r.TestContext.Errorf("Unexpected stderr messages found.\nExpected: none\nActual:\n'%s'", r.Stderr)
}
if r.Stdout != expected+"\n" { // Output will always have a end of output newline.
r.TestContext.Errorf("Unexpected stdout found.\nExpected:\n'%s'\nActual:\n'%s'", expected, r.Stdout)
fullExpected := expected + "\n" // Output will always have a end of output newline.
if r.Stdout != fullExpected { // Output will always have a end of output newline.
r.TestContext.Errorf("Unexpected stdout found.\nExpected:\n'%s'\nActual:\n'%s'", fullExpected, r.Stdout)
}
}

func (r *RunResult) expectError(expected string) {
if r.Stderr != expected+"\n" { // Output will always have a end of output newline.
r.TestContext.Errorf("Unexpected stderr found.\nExpected:\n'%s'\nActual:\n'%s'", expected, r.Stderr)
fullExpected := expected + "\n" // Output will always have a end of output newline.
if r.Stderr != fullExpected {
r.TestContext.Errorf("Unexpected stderr found.\nExpected:\n'%s'\nActual:\n'%s'", fullExpected, r.Stderr)
}
}

Expand All @@ -62,6 +64,11 @@ func TestNormalizedList_SinglePackageExists_StdoutsSinglePackageNameVersionPair(
result.expectSuccessfulOut("xdot=1.2-3")
}

func TestNormalizedList_VersionContainsColon_StdoutsEntireVersion(t *testing.T) {
var result = run(t, "normalized-list", "default-jre")
result.expectSuccessfulOut("default-jre=2:1.17-74")
}

func TestNormalizedList_NonExistentPackageName_StderrsAptCacheErrors(t *testing.T) {
var result = run(t, "normalized-list", "nonexistentpackagename")
result.expectError(
Expand Down

0 comments on commit 7c7bced

Please sign in to comment.