make filecontent test a go test

This commit is contained in:
Aaron Meihm 2017-07-19 16:38:35 -05:00
Родитель b848820482
Коммит f750b762d2
7 изменённых файлов: 173 добавлений и 178 удалений

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

@ -45,3 +45,175 @@ var hasLinePolicyDoc = `
func TestHasLinePolicy(t *testing.T) {
genericTestExec(t, hasLinePolicyDoc)
}
// Used in TestFileContentPolicy
var fileContentPolicyDoc = `
{
"variables": [
{ "key": "root", "value": "./test/filecontent" }
],
"objects": [
{
"object": "nosuchfile",
"filecontent": {
"path": "${root}",
"file": "nosuchfile",
"expression": ".*"
}
},
{
"object": "testfile0-test",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": ".*(Test).*"
}
},
{
"object": "testfile0-all",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": "(.*)"
}
},
{
"object": "testfile0-regex",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": "^(T\\S+).*"
}
},
{
"object": "testfile1-version",
"filecontent": {
"path": "${root}",
"file": ".*file1",
"expression": "^Version = (\\S+)"
}
},
{
"object": "testfile2-version",
"filecontent": {
"path": "${root}",
"file": ".*file2",
"expression": "^Version = (\\S+)"
}
},
{
"object": "anyfile",
"filecontent": {
"path": "${root}/",
"file": ".*",
"expression": "(.*)"
}
}
],
"tests": [
{
"test": "simplecontent0",
"description": "test with nonexistent file",
"expectedresult": false,
"object": "nosuchfile"
},
{
"test": "simplecontent1",
"expectedresult": true,
"object": "testfile0-test"
},
{
"test": "simplecontent2",
"expectedresult": true,
"object": "testfile0-all",
"regexp": {
"value": "Test"
}
},
{
"test": "simplecontent3",
"expectedresult": true,
"object": "testfile0-regex",
"regexp": {
"value": "Test"
}
},
{
"test": "filecontent0",
"expectedresult": true,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
}
},
{
"test": "filecontent1",
"expectedresult": false,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
},
"if": [ "simplecontent0" ]
},
{
"test": "filecontent2",
"expectedresult": true,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
},
"if": [ "simplecontent1" ]
},
{
"test": "filecontent3",
"description": "version is ok",
"expectedresult": false,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.4z"
}
},
{
"test": "filecontent4",
"description": "version is ok",
"expectedresult": false,
"object": "testfile2-version",
"evr": {
"operation": "<",
"value": "0.4z"
}
},
{
"test": "anyfile0",
"expectedresult": true,
"object": "anyfile"
}
]
}
`
func TestFileContentPolicy(t *testing.T) {
genericTestExec(t, fileContentPolicyDoc)
}

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

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

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

@ -1,13 +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 -f test.json; \
test.json: test-template.json
cat test-template.json | sed 's,REPLACE_IN_MAKEFILE,$(shell pwd),' > test.json
clean:
rm -f test.json

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

@ -1,164 +0,0 @@
{
"variables": [
{ "key": "root", "value": "REPLACE_IN_MAKEFILE" }
],
"objects": [
{
"object": "nosuchfile",
"filecontent": {
"path": "${root}",
"file": "nosuchfile",
"expression": ".*"
}
},
{
"object": "testfile0-test",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": ".*(Test).*"
}
},
{
"object": "testfile0-all",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": "(.*)"
}
},
{
"object": "testfile0-regex",
"filecontent": {
"path": "${root}",
"file": "testfile0",
"expression": "^(T\\S+).*"
}
},
{
"object": "testfile1-version",
"filecontent": {
"path": "${root}",
"file": ".*file1",
"expression": "^Version = (\\S+)"
}
},
{
"object": "testfile2-version",
"filecontent": {
"path": "${root}",
"file": ".*file2",
"expression": "^Version = (\\S+)"
}
},
{
"object": "anyfile",
"filecontent": {
"path": "${root}/data",
"file": ".*",
"expression": "(.*)"
}
}
],
"tests": [
{
"test": "simplecontent0",
"description": "test with nonexistent file",
"expectedresult": false,
"object": "nosuchfile"
},
{
"test": "simplecontent1",
"expectedresult": true,
"object": "testfile0-test"
},
{
"test": "simplecontent2",
"expectedresult": true,
"object": "testfile0-all",
"regexp": {
"value": "Test"
}
},
{
"test": "simplecontent3",
"expectedresult": true,
"object": "testfile0-regex",
"regexp": {
"value": "Test"
}
},
{
"test": "filecontent0",
"expectedresult": true,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
}
},
{
"test": "filecontent1",
"expectedresult": false,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
},
"if": [ "simplecontent0" ]
},
{
"test": "filecontent2",
"expectedresult": true,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.6"
},
"if": [ "simplecontent1" ]
},
{
"test": "filecontent3",
"description": "version is ok",
"expectedresult": false,
"object": "testfile1-version",
"evr": {
"operation": "<",
"value": "0.4z"
}
},
{
"test": "filecontent4",
"description": "version is ok",
"expectedresult": false,
"object": "testfile2-version",
"evr": {
"operation": "<",
"value": "0.4z"
}
},
{
"test": "anyfile0",
"expectedresult": true,
"object": "anyfile"
}
]
}

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

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

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