From 5c9e6c03af10d3453b49902231fe527cc7e842ae Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Wed, 18 Jul 2018 17:08:44 +0200 Subject: [PATCH] import-boss: add tests --- .travis.yml | 2 +- examples/import-boss/Makefile | 28 +++++++++++++++++++ examples/import-boss/tests/inverse/a/doc.go | 6 ++++ examples/import-boss/tests/inverse/b/doc.go | 7 +++++ examples/import-boss/tests/inverse/c/doc.go | 7 +++++ examples/import-boss/tests/inverse/d/doc.go | 6 ++++ examples/import-boss/tests/inverse/lib/doc.go | 6 ++++ .../import-boss/tests/inverse/lib/lib_test.go | 5 ++++ .../inverse/lib/nonprod/.import-restrictions | 9 ++++++ .../tests/inverse/lib/nonprod/doc.go | 2 ++ .../inverse/lib/private/.import-restrictions | 11 ++++++++ .../tests/inverse/lib/private/doc.go | 1 + .../tests/inverse/lib/public/doc.go | 1 + .../tests/inverse/lib/quarantine/doc.go | 6 ++++ .../tests/rules/a/.import-restrictions | 11 ++++++++ examples/import-boss/tests/rules/a/doc.go | 5 ++++ .../tests/rules/b/.import-restrictions | 11 ++++++++ examples/import-boss/tests/rules/b/doc.go | 6 ++++ examples/import-boss/tests/rules/c/doc.go | 1 + .../tests/rules/nested/.import-restrictions | 10 +++++++ .../import-boss/tests/rules/nested/doc.go | 5 ++++ .../rules/nested/nested/.import-restrictions | 10 +++++++ .../tests/rules/nested/nested/doc.go | 5 ++++ .../nested/nested/nested/.import-restrictions | 10 +++++++ .../tests/rules/nested/nested/nested/doc.go | 5 ++++ .../rules/nested/nested/nested/inherit/doc.go | 5 ++++ 26 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 examples/import-boss/Makefile create mode 100644 examples/import-boss/tests/inverse/a/doc.go create mode 100644 examples/import-boss/tests/inverse/b/doc.go create mode 100644 examples/import-boss/tests/inverse/c/doc.go create mode 100644 examples/import-boss/tests/inverse/d/doc.go create mode 100644 examples/import-boss/tests/inverse/lib/doc.go create mode 100644 examples/import-boss/tests/inverse/lib/lib_test.go create mode 100644 examples/import-boss/tests/inverse/lib/nonprod/.import-restrictions create mode 100644 examples/import-boss/tests/inverse/lib/nonprod/doc.go create mode 100644 examples/import-boss/tests/inverse/lib/private/.import-restrictions create mode 100644 examples/import-boss/tests/inverse/lib/private/doc.go create mode 100644 examples/import-boss/tests/inverse/lib/public/doc.go create mode 100644 examples/import-boss/tests/inverse/lib/quarantine/doc.go create mode 100644 examples/import-boss/tests/rules/a/.import-restrictions create mode 100644 examples/import-boss/tests/rules/a/doc.go create mode 100644 examples/import-boss/tests/rules/b/.import-restrictions create mode 100644 examples/import-boss/tests/rules/b/doc.go create mode 100644 examples/import-boss/tests/rules/c/doc.go create mode 100644 examples/import-boss/tests/rules/nested/.import-restrictions create mode 100644 examples/import-boss/tests/rules/nested/doc.go create mode 100644 examples/import-boss/tests/rules/nested/nested/.import-restrictions create mode 100644 examples/import-boss/tests/rules/nested/nested/doc.go create mode 100644 examples/import-boss/tests/rules/nested/nested/nested/.import-restrictions create mode 100644 examples/import-boss/tests/rules/nested/nested/nested/doc.go create mode 100644 examples/import-boss/tests/rules/nested/nested/nested/inherit/doc.go diff --git a/.travis.yml b/.travis.yml index 1fd593ac..3ed9b349 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ jobs: - go test -v ./... - stage: Verify examples script: - - go run ./examples/import-boss/main.go -i k8s.io/gengo/... --verify-only + - go run ./examples/import-boss/main.go -i $(go list k8s.io/gengo/... | grep -v import-boss/tests | paste -sd',' -) --verify-only diff --git a/examples/import-boss/Makefile b/examples/import-boss/Makefile new file mode 100644 index 00000000..90e58974 --- /dev/null +++ b/examples/import-boss/Makefile @@ -0,0 +1,28 @@ +TOOL=import-boss + +all: test + +test: build test_rules test_inverse + +build: + @go build -o /tmp/$(TOOL) + +test_rules: + /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/a) + ! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/rules/b) + /tmp/$(TOOL) --logtostderr --v=4 -i ./tests/rules/c + ! /tmp/$(TOOL) --logtostderr --v=4 -i ./tests/rules/nested + /tmp/$(TOOL) --logtostderr --v=4 -i ./tests/rules/nested/nested + ! /tmp/$(TOOL) --logtostderr --v=4 -i ./tests/rules/nested/nested/nested + ! /tmp/$(TOOL) --logtostderr --v=4 -i ./tests/rules/nested/nested/nested/inherit + +test_inverse: + /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/a ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -) + ! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/b ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -) + /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/c ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -) + ! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/d ./tests/inverse/lib/... | grep -v quarantine | paste -sd',' -) + ! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/lib/... | paste -sd',' -) + + ! /tmp/$(TOOL) --logtostderr --v=4 -i $$(go list ./tests/inverse/lib/... | paste -sd',' -) + +.PHONY: build test test_rules test_inverse diff --git a/examples/import-boss/tests/inverse/a/doc.go b/examples/import-boss/tests/inverse/a/doc.go new file mode 100644 index 00000000..4a831853 --- /dev/null +++ b/examples/import-boss/tests/inverse/a/doc.go @@ -0,0 +1,6 @@ +// a only imports public packages. +package a + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public" +) diff --git a/examples/import-boss/tests/inverse/b/doc.go b/examples/import-boss/tests/inverse/b/doc.go new file mode 100644 index 00000000..c9044187 --- /dev/null +++ b/examples/import-boss/tests/inverse/b/doc.go @@ -0,0 +1,7 @@ +// b only imports public and private packages. The latter it shouldn't. +package b + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private" + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public" +) diff --git a/examples/import-boss/tests/inverse/c/doc.go b/examples/import-boss/tests/inverse/c/doc.go new file mode 100644 index 00000000..7438e478 --- /dev/null +++ b/examples/import-boss/tests/inverse/c/doc.go @@ -0,0 +1,7 @@ +// c imports the library root, which in turn imports the public and private packages. This is fine because +// the private package is not directly imported. +package c + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib" +) diff --git a/examples/import-boss/tests/inverse/d/doc.go b/examples/import-boss/tests/inverse/d/doc.go new file mode 100644 index 00000000..3e61b6ce --- /dev/null +++ b/examples/import-boss/tests/inverse/d/doc.go @@ -0,0 +1,6 @@ +// c imports non-prod code. It shouldn't. +package d + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/nonprod" +) diff --git a/examples/import-boss/tests/inverse/lib/doc.go b/examples/import-boss/tests/inverse/lib/doc.go new file mode 100644 index 00000000..6ed837cd --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/doc.go @@ -0,0 +1,6 @@ +package lib + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private" + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public" +) diff --git a/examples/import-boss/tests/inverse/lib/lib_test.go b/examples/import-boss/tests/inverse/lib/lib_test.go new file mode 100644 index 00000000..78a02b2a --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/lib_test.go @@ -0,0 +1,5 @@ +package lib + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/nonprod" +) diff --git a/examples/import-boss/tests/inverse/lib/nonprod/.import-restrictions b/examples/import-boss/tests/inverse/lib/nonprod/.import-restrictions new file mode 100644 index 00000000..c0e2acff --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/nonprod/.import-restrictions @@ -0,0 +1,9 @@ +{ + "InverseRules": [{ + "Transitive": true, + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/inverse/lib" + ] + }] +} diff --git a/examples/import-boss/tests/inverse/lib/nonprod/doc.go b/examples/import-boss/tests/inverse/lib/nonprod/doc.go new file mode 100644 index 00000000..88dacaf0 --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/nonprod/doc.go @@ -0,0 +1,2 @@ +// nonprod is non-production code that should not be linked into any outside package. +package nonprod \ No newline at end of file diff --git a/examples/import-boss/tests/inverse/lib/private/.import-restrictions b/examples/import-boss/tests/inverse/lib/private/.import-restrictions new file mode 100644 index 00000000..9bcbd35e --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/private/.import-restrictions @@ -0,0 +1,11 @@ +{ + "InverseRules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/inverse/lib" + ], + "ForbiddenPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/inverse/lib/quarantine" + ] + }] +} diff --git a/examples/import-boss/tests/inverse/lib/private/doc.go b/examples/import-boss/tests/inverse/lib/private/doc.go new file mode 100644 index 00000000..735e4dc8 --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/private/doc.go @@ -0,0 +1 @@ +package private diff --git a/examples/import-boss/tests/inverse/lib/public/doc.go b/examples/import-boss/tests/inverse/lib/public/doc.go new file mode 100644 index 00000000..768b9119 --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/public/doc.go @@ -0,0 +1 @@ +package public \ No newline at end of file diff --git a/examples/import-boss/tests/inverse/lib/quarantine/doc.go b/examples/import-boss/tests/inverse/lib/quarantine/doc.go new file mode 100644 index 00000000..82d777e4 --- /dev/null +++ b/examples/import-boss/tests/inverse/lib/quarantine/doc.go @@ -0,0 +1,6 @@ +// quarantine is inside the library, but should not import the private package. But it does! +package quarantine + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/private" +) diff --git a/examples/import-boss/tests/rules/a/.import-restrictions b/examples/import-boss/tests/rules/a/.import-restrictions new file mode 100644 index 00000000..0edffb47 --- /dev/null +++ b/examples/import-boss/tests/rules/a/.import-restrictions @@ -0,0 +1,11 @@ +{ + "Rules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/b" + ], + "ForbiddenPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/c" + ] + }] +} diff --git a/examples/import-boss/tests/rules/a/doc.go b/examples/import-boss/tests/rules/a/doc.go new file mode 100644 index 00000000..a8478f9a --- /dev/null +++ b/examples/import-boss/tests/rules/a/doc.go @@ -0,0 +1,5 @@ +package a + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/b" +) diff --git a/examples/import-boss/tests/rules/b/.import-restrictions b/examples/import-boss/tests/rules/b/.import-restrictions new file mode 100644 index 00000000..49f2c702 --- /dev/null +++ b/examples/import-boss/tests/rules/b/.import-restrictions @@ -0,0 +1,11 @@ +{ + "Rules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + "" + ], + "ForbiddenPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/c" + ] + }] +} diff --git a/examples/import-boss/tests/rules/b/doc.go b/examples/import-boss/tests/rules/b/doc.go new file mode 100644 index 00000000..9cc55a68 --- /dev/null +++ b/examples/import-boss/tests/rules/b/doc.go @@ -0,0 +1,6 @@ +// b only public and private packages. The latter it shouldn't. +package b + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/c" +) diff --git a/examples/import-boss/tests/rules/c/doc.go b/examples/import-boss/tests/rules/c/doc.go new file mode 100644 index 00000000..7f96c221 --- /dev/null +++ b/examples/import-boss/tests/rules/c/doc.go @@ -0,0 +1 @@ +package c diff --git a/examples/import-boss/tests/rules/nested/.import-restrictions b/examples/import-boss/tests/rules/nested/.import-restrictions new file mode 100644 index 00000000..e8c54579 --- /dev/null +++ b/examples/import-boss/tests/rules/nested/.import-restrictions @@ -0,0 +1,10 @@ +{ + "Rules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + ], + "ForbiddenPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/c" + ] + }] +} diff --git a/examples/import-boss/tests/rules/nested/doc.go b/examples/import-boss/tests/rules/nested/doc.go new file mode 100644 index 00000000..45635d38 --- /dev/null +++ b/examples/import-boss/tests/rules/nested/doc.go @@ -0,0 +1,5 @@ +package nested + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/c" +) diff --git a/examples/import-boss/tests/rules/nested/nested/.import-restrictions b/examples/import-boss/tests/rules/nested/nested/.import-restrictions new file mode 100644 index 00000000..c3264425 --- /dev/null +++ b/examples/import-boss/tests/rules/nested/nested/.import-restrictions @@ -0,0 +1,10 @@ +{ + "Rules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/c" + ], + "ForbiddenPrefixes": [ + ] + }] +} diff --git a/examples/import-boss/tests/rules/nested/nested/doc.go b/examples/import-boss/tests/rules/nested/nested/doc.go new file mode 100644 index 00000000..8a91579d --- /dev/null +++ b/examples/import-boss/tests/rules/nested/nested/doc.go @@ -0,0 +1,5 @@ +package nested + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/c" +) \ No newline at end of file diff --git a/examples/import-boss/tests/rules/nested/nested/nested/.import-restrictions b/examples/import-boss/tests/rules/nested/nested/nested/.import-restrictions new file mode 100644 index 00000000..1d49424e --- /dev/null +++ b/examples/import-boss/tests/rules/nested/nested/nested/.import-restrictions @@ -0,0 +1,10 @@ +{ + "Rules": [{ + "SelectorRegexp": "k8s[.]io/gengo", + "AllowedPrefixes": [ + ], + "ForbiddenPrefixes": [ + "k8s.io/gengo/examples/import-boss/tests/rules/c" + ] + }] +} diff --git a/examples/import-boss/tests/rules/nested/nested/nested/doc.go b/examples/import-boss/tests/rules/nested/nested/nested/doc.go new file mode 100644 index 00000000..45635d38 --- /dev/null +++ b/examples/import-boss/tests/rules/nested/nested/nested/doc.go @@ -0,0 +1,5 @@ +package nested + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/c" +) diff --git a/examples/import-boss/tests/rules/nested/nested/nested/inherit/doc.go b/examples/import-boss/tests/rules/nested/nested/nested/inherit/doc.go new file mode 100644 index 00000000..54c0f5d9 --- /dev/null +++ b/examples/import-boss/tests/rules/nested/nested/nested/inherit/doc.go @@ -0,0 +1,5 @@ +package inherit + +import ( + _ "k8s.io/gengo/examples/import-boss/tests/rules/c" +)