diff --git a/fileops_test.go b/fileops_test.go index 9e79d0a..0aa9f72 100644 --- a/fileops_test.go +++ b/fileops_test.go @@ -217,3 +217,99 @@ var fileContentPolicyDoc = ` func TestFileContentPolicy(t *testing.T) { genericTestExec(t, fileContentPolicyDoc) } + +var fileNamePolicyDoc = ` +{ + "variables": [ + { "key": "root", "value": "./test/filename" } + ], + + "objects": [ + { + "object": "anyfile", + "filename": { + "path": "${root}", + "file": "(.*)" + } + }, + + { + "object": "nosuchfile", + "filename": { + "path": "${root}", + "file": ".*(nosuchfile).*" + } + }, + + { + "object": "fileversion", + "filename": { + "path": "${root}", + "file": "file-(\\S+).txt" + } + }, + + { + "object": "testfile0", + "filename": { + "path": "${root}", + "file": "^(testfile0)$" + } + } + ], + + "tests": [ + { + "test": "filename0", + "expectedresult": true, + "object": "anyfile" + }, + + { + "test": "filename1", + "expectedresult": false, + "object": "nosuchfile" + }, + + { + "test": "filename2", + "expectedresult": true, + "object": "fileversion", + "evr": { + "operation": "<", + "value": "1.6.0" + } + }, + + { + "test": "filename3", + "expectedresult": false, + "object": "fileversion", + "evr": { + "operation": "<", + "value": "1.1.0" + } + }, + + { + "test": "filename4", + "expectedresult": true, + "object": "fileversion", + "regexp": { + "value": "1.2.3" + } + }, + + { + "test": "filename5", + "expectedresult": true, + "object": "testfile0" + } + + ] +} +` + +func TestFileNamePolicy(t *testing.T) { + genericTestExec(t, fileNamePolicyDoc) +} diff --git a/test/Makefile b/test/Makefile index 4743aa6..a139684 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TESTDIRS = filename concat raw import-chain tags +TESTDIRS = concat raw import-chain tags all: diff --git a/test/filename/Makefile b/test/filename/Makefile deleted file mode 100644 index df69fd4..0000000 --- a/test/filename/Makefile +++ /dev/null @@ -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 diff --git a/test/filename/data/file-1.2.3.txt b/test/filename/file-1.2.3.txt similarity index 100% rename from test/filename/data/file-1.2.3.txt rename to test/filename/file-1.2.3.txt diff --git a/test/filename/data/file-1.5.0.txt b/test/filename/file-1.5.0.txt similarity index 100% rename from test/filename/data/file-1.5.0.txt rename to test/filename/file-1.5.0.txt diff --git a/test/filename/test-template.json b/test/filename/test-template.json deleted file mode 100644 index a1f1e5f..0000000 --- a/test/filename/test-template.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "variables": [ - { "key": "root", "value": "REPLACE_IN_MAKEFILE" } - ], - - "objects": [ - { - "object": "anyfile", - "filename": { - "path": "${root}", - "file": "(.*)" - } - }, - - { - "object": "nosuchfile", - "filename": { - "path": "${root}", - "file": ".*(nosuchfile).*" - } - }, - - { - "object": "fileversion", - "filename": { - "path": "${root}", - "file": "file-(\\S+).txt" - } - }, - - { - "object": "testfile0", - "filename": { - "path": "${root}", - "file": "^(testfile0)$" - } - } - ], - - "tests": [ - { - "test": "filename0", - "expectedresult": true, - "object": "anyfile" - }, - - { - "test": "filename1", - "expectedresult": false, - "object": "nosuchfile" - }, - - { - "test": "filename2", - "expectedresult": true, - "object": "fileversion", - "evr": { - "operation": "<", - "value": "1.6.0" - } - }, - - { - "test": "filename3", - "expectedresult": false, - "object": "fileversion", - "evr": { - "operation": "<", - "value": "1.1.0" - } - }, - - { - "test": "filename4", - "expectedresult": true, - "object": "fileversion", - "regexp": { - "value": "1.2.3" - } - }, - - { - "test": "filename5", - "expectedresult": true, - "object": "testfile0" - } - - ] -} diff --git a/test/filename/data/testfile0 b/test/filename/testfile0 similarity index 100% rename from test/filename/data/testfile0 rename to test/filename/testfile0