Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Commit

Permalink
fix verification of versioned packaged
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Jun 25, 2019
1 parent 5b70945 commit cba20b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/phases/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func addPackageCommands(sys *Config, commands *Commands) {
if p.Uninstall {
ops.uninstall = appendStrings(ops.uninstall, p.Name)
} else {
ops.install = appendStrings(ops.install, p.Name)
ops.install = appendStrings(ops.install, p.VersionedName())
}
managers[getKeyFromTags(p.Flags...)] = ops
}
Expand All @@ -93,12 +93,11 @@ func addPackageCommands(sys *Config, commands *Commands) {
var ok bool
if ops, ok = managers[getKeyFromTags(os.GetTags()...)]; !ok {
ops = packageOperations{tags: os.GetTags()}

}
if p.Uninstall {
ops.uninstall = appendStrings(ops.uninstall, p.Name)
} else {
ops.install = appendStrings(ops.install, p.Name)
ops.install = appendStrings(ops.install, p.VersionedName())
}
managers[getKeyFromTags(os.GetTags()...)] = ops
}
Expand Down Expand Up @@ -148,27 +147,29 @@ func (p packages) Verify(cfg *Config, results *VerifyResults, flags ...Flag) boo
results.Fail("Unable to find OS for tags %s", flags)
return false
}

for _, p := range *cfg.Packages {
if !MatchesAny(flags, p.Flags) {
continue
}
log.Tracef("Verifying package: %s, version: %s", p.Name, p.Version)
installed := os.GetPackageManager().GetInstalledVersion(p.Name)
if p.Uninstall {
if installed == "" {
results.Pass("%s is not installed", p)
} else {
results.Fail("%s-%s should not be installed", p, installed)
results.Fail("%s should not be installed", p)
verify = false
}
} else if p.Version == "" && installed != "" {
results.Pass("%s-%s is installed", p, installed)
results.Pass("%s is installed with any version: %s", p, installed)
} else if p.Version == "" && installed == "" {
results.Fail("%s is not installed, any version required", p)
verify = false
} else if installed == p.Version {
results.Pass("%s-%s is installed", p, installed)
results.Pass("%s is installed with expected version: %s", p, installed)
} else {
results.Fail("%s-%s is installed, but not the correct version: %s", p.Name, installed, p.Version)
results.Fail("%s is installed, but expected %s, got %s", p.Name, p.Version, installed)
verify = false
}
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/types/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func (p Package) String() string {
return p.Name + fmt.Sprintf("%s", p.Flags)
}

func (p Package) VersionedName() string {
if p.Version == "" {
return p.Name
}
return p.Name + "=" + p.Version
}

//AddPackage is a helper function to add new packages
func (cfg *Config) AddPackage(name string, flag *Flag) *Config {
pkg := Package{
Expand Down Expand Up @@ -108,6 +115,12 @@ func (p *Package) UnmarshalYAML(node *yaml.Node) error {
p.Name = node.Value[1:]
p.Mark = true
}

if strings.Contains(p.Name, "=") {
parts := strings.Split(p.Name, "=")
p.Name = parts[0]
p.Version = parts[len(parts)-1]
}
comment := node.LineComment
if !strings.Contains(comment, "#") {
return nil
Expand Down

0 comments on commit cba20b2

Please sign in to comment.