This commit is contained in:
Aaron Meihm 2017-07-19 15:13:49 -05:00
Родитель 78509186e4
Коммит d2cfc553e9
5 изменённых файлов: 168 добавлений и 131 удалений

Просмотреть файл

@ -38,6 +38,17 @@ func (d *Document) Validate() error {
return nil return nil
} }
// GetTest returns a given test from the document, given the identifier
func (d *Document) GetTest(identifier string) (ret Test, err error) {
for _, x := range d.Tests {
if x.TestID == identifier {
return x, nil
}
}
err = fmt.Errorf("test %v not found", identifier)
return
}
// GetTestIdentifiers returns the test identifiers for all tests present in // GetTestIdentifiers returns the test identifiers for all tests present in
// the document. // the document.
func (d *Document) GetTestIdentifiers() []string { func (d *Document) GetTestIdentifiers() []string {

Просмотреть файл

@ -9,9 +9,165 @@ package scribe_test
import ( import (
"github.com/mozilla/scribe" "github.com/mozilla/scribe"
"strings"
"testing" "testing"
) )
// Used in TestPackagePolicy
var packagePolicyDoc = `
{
"objects": [
{
"object": "openssl-package",
"package": {
"name": "openssl"
}
},
{
"object": "libbind-package",
"package": {
"name": "libbind"
}
},
{
"object": "grub-common-package",
"package": {
"name": "grub-common"
}
},
{
"object": "kernel-package-newest",
"package": {
"name": "kernel",
"onlynewest": true
}
}
],
"tests": [
{
"test": "package0",
"expectedresult": true,
"object": "openssl-package"
},
{
"test": "package1",
"expectedresult": true,
"object": "libbind-package",
"evr": {
"operation": "=",
"value": "1:9.9.5.dfsg-4.3"
}
},
{
"test": "package2",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta1"
}
},
{
"test": "package3",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta2"
}
},
{
"test": "package4",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.01-beta2"
}
},
{
"test": "package5",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta3"
},
"if": [ "package2" ]
},
{
"test": "package6",
"expecterror": true,
"object": "openssl-package",
"evr": {
"operation": "badop",
"value": "1.0.1e"
}
},
{
"test": "package7",
"expectedresult": true,
"object": "openssl-package",
"evr": {
"operation": ">",
"value": "1.0.1d"
}
},
{
"test": "package8",
"expectedresult": false,
"object": "kernel-package-newest",
"evr": {
"operation": "<",
"value": "2.6.32-573.8.1.el6.x86_64"
}
}
]
}
`
func TestPackagePolicy(t *testing.T) {
rdr := strings.NewReader(packagePolicyDoc)
scribe.Bootstrap()
scribe.TestHooks(true)
doc, err := scribe.LoadDocument(rdr)
if err != nil {
t.Fatalf("scribe.LoadDocument: %v", err)
}
err = scribe.AnalyzeDocument(doc)
if err != nil {
t.Fatalf("scribe.AnalyzeDocument: %v", err)
}
// Get results for each test and make sure the result matches what
// expectedresult is set to
testids := doc.GetTestIdentifiers()
for _, x := range testids {
stest, err := doc.GetTest(x)
if err != nil {
t.Fatalf("Document.GetTest: %v", err)
}
sres, err := scribe.GetResults(&doc, x)
if err != nil {
t.Fatalf("scribe.GetResults: %v", err)
}
if sres.MasterResult != stest.ExpectedResult {
t.Fatalf("result incorrect for test %v", x)
}
}
}
func TestPackageQuery(t *testing.T) { func TestPackageQuery(t *testing.T) {
scribe.Bootstrap() scribe.Bootstrap()
scribe.TestHooks(true) scribe.TestHooks(true)

Просмотреть файл

@ -1,4 +1,4 @@
TESTDIRS = filecontent filename package concat raw import-chain hasline tags TESTDIRS = filecontent filename concat raw import-chain hasline tags
all: all:

Просмотреть файл

@ -1,9 +0,0 @@
all:
runtests: test.json
ifndef SCRIBECMD
$(error SCRIBECMD is undefined, tests must be ran from the root of the repository)
endif
$(SCRIBECMD) -e -t -f test.json; \
clean:

Просмотреть файл

@ -1,121 +0,0 @@
{
"objects": [
{
"object": "openssl-package",
"package": {
"name": "openssl"
}
},
{
"object": "libbind-package",
"package": {
"name": "libbind"
}
},
{
"object": "grub-common-package",
"package": {
"name": "grub-common"
}
},
{
"object": "kernel-package-newest",
"package": {
"name": "kernel",
"onlynewest": true
}
}
],
"tests": [
{
"test": "package0",
"expectedresult": true,
"object": "openssl-package"
},
{
"test": "package1",
"expectedresult": true,
"object": "libbind-package",
"evr": {
"operation": "=",
"value": "1:9.9.5.dfsg-4.3"
}
},
{
"test": "package2",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta1"
}
},
{
"test": "package3",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta2"
}
},
{
"test": "package4",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.01-beta2"
}
},
{
"test": "package5",
"expectedresult": false,
"object": "grub-common-package",
"evr": {
"operation": "<",
"value": "2.02-beta3"
},
"if": [ "package2" ]
},
{
"test": "package6",
"expecterror": true,
"object": "openssl-package",
"evr": {
"operation": "badop",
"value": "1.0.1e"
}
},
{
"test": "package7",
"expectedresult": true,
"object": "openssl-package",
"evr": {
"operation": ">",
"value": "1.0.1d"
}
},
{
"test": "package8",
"expectedresult": false,
"object": "kernel-package-newest",
"evr": {
"operation": "<",
"value": "2.6.32-573.8.1.el6.x86_64"
}
}
]
}