зеркало из https://github.com/mozilla/scribe.git
generic package query functionality and test
This commit is contained in:
Родитель
acfca2a23a
Коммит
18a620ea35
|
@ -0,0 +1,26 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
//
|
||||
// Contributor:
|
||||
// - Aaron Meihm ameihm@mozilla.com
|
||||
|
||||
package scribe_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"scribe"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPackageQuery(t *testing.T) {
|
||||
scribe.Bootstrap()
|
||||
scribe.TestHooks(true)
|
||||
pinfo := scribe.QueryPackages()
|
||||
for _, x := range pinfo {
|
||||
fmt.Println(x.Name, x.Version, x.Type)
|
||||
}
|
||||
if len(pinfo) != 5 {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
|
@ -25,6 +25,27 @@ type pkgmgrInfo struct {
|
|||
pkgtype string
|
||||
}
|
||||
|
||||
// Package information from the system as returned by QueryPackages().
|
||||
type PackageInfo struct {
|
||||
Name string `json:"name"` // Package name.
|
||||
Version string `json:"version"` // Package version.
|
||||
Type string `json:"type"` // Package type.
|
||||
}
|
||||
|
||||
// Query packages on the system, returning a slice of all identified packages
|
||||
// in PackageInfo form.
|
||||
func QueryPackages() []PackageInfo {
|
||||
ret := make([]PackageInfo, 0)
|
||||
for _, x := range getAllPackages().results {
|
||||
np := PackageInfo{}
|
||||
np.Name = x.name
|
||||
np.Version = x.version
|
||||
np.Type = x.pkgtype
|
||||
ret = append(ret, np)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func getPackage(name string) (ret pkgmgrResult) {
|
||||
ret.results = make([]pkgmgrInfo, 0)
|
||||
if !pkgmgrInitialized {
|
||||
|
@ -42,6 +63,18 @@ func getPackage(name string) (ret pkgmgrResult) {
|
|||
return
|
||||
}
|
||||
|
||||
func getAllPackages() pkgmgrResult {
|
||||
ret := pkgmgrResult{}
|
||||
ret.results = make([]pkgmgrInfo, 0)
|
||||
if !pkgmgrInitialized {
|
||||
pkgmgrInit()
|
||||
}
|
||||
for _, x := range pkgmgrCache {
|
||||
ret.results = append(ret.results, x)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func pkgmgrInit() {
|
||||
debugPrint("pkgmgrInit(): initializing package manager...\n")
|
||||
pkgmgrCache = make([]pkgmgrInfo, 0)
|
||||
|
|
Загрузка…
Ссылка в новой задаче