mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Dependency to string.
This commit is contained in:
Vendored
+20
@@ -193,6 +193,26 @@ func (d *Dependency) Hash() string {
|
|||||||
return fmt.Sprintf("%s:%s:%d:%s", d.Architecture, d.Pkg, d.Relation, d.Version)
|
return fmt.Sprintf("%s:%s:%d:%s", d.Architecture, d.Pkg, d.Relation, d.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String produces human-readable representation
|
||||||
|
func (d *Dependency) String() string {
|
||||||
|
var rel string
|
||||||
|
switch d.Relation {
|
||||||
|
case VersionEqual:
|
||||||
|
rel = "="
|
||||||
|
case VersionGreater:
|
||||||
|
rel = ">>"
|
||||||
|
case VersionLess:
|
||||||
|
rel = "<<"
|
||||||
|
case VersionGreaterOrEqual:
|
||||||
|
rel = ">="
|
||||||
|
case VersionLessOrEqual:
|
||||||
|
rel = "<="
|
||||||
|
case VersionDontCare:
|
||||||
|
return fmt.Sprintf("%s [%s]", d.Pkg, d.Architecture)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s (%s %s) [%s]", d.Pkg, rel, d.Version, d.Architecture)
|
||||||
|
}
|
||||||
|
|
||||||
// parseDependency parses dependency in format "pkg (>= 1.35)" into parts
|
// parseDependency parses dependency in format "pkg (>= 1.35)" into parts
|
||||||
func parseDependency(dep string) (d Dependency, err error) {
|
func parseDependency(dep string) (d Dependency, err error) {
|
||||||
if !strings.HasSuffix(dep, ")") {
|
if !strings.HasSuffix(dep, ")") {
|
||||||
|
|||||||
Vendored
+10
@@ -153,3 +153,13 @@ func (s *VersionSuite) TestParseDependency(c *C) {
|
|||||||
d, e = parseDependency("dpkg==1.6)")
|
d, e = parseDependency("dpkg==1.6)")
|
||||||
c.Check(e, ErrorMatches, "unable to parse.*")
|
c.Check(e, ErrorMatches, "unable to parse.*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *VersionSuite) TestDependencyString(c *C) {
|
||||||
|
d, _ := parseDependency("dpkg(>>1.6)")
|
||||||
|
d.Architecture = "i386"
|
||||||
|
c.Check(d.String(), Equals, "dpkg (>> 1.6) [i386]")
|
||||||
|
|
||||||
|
d, _ = parseDependency("dpkg")
|
||||||
|
d.Architecture = "i386"
|
||||||
|
c.Check(d.String(), Equals, "dpkg [i386]")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user