Skip to content

Commit

Permalink
import-boss: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts authored and eloyekunle committed Sep 28, 2019
1 parent 5fd574f commit 5c9e6c0
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions examples/import-boss/Makefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions examples/import-boss/tests/inverse/a/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// a only imports public packages.
package a

import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/public"
)
7 changes: 7 additions & 0 deletions examples/import-boss/tests/inverse/b/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
7 changes: 7 additions & 0 deletions examples/import-boss/tests/inverse/c/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
6 changes: 6 additions & 0 deletions examples/import-boss/tests/inverse/d/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
6 changes: 6 additions & 0 deletions examples/import-boss/tests/inverse/lib/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
5 changes: 5 additions & 0 deletions examples/import-boss/tests/inverse/lib/lib_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package lib

import (
_ "k8s.io/gengo/examples/import-boss/tests/inverse/lib/nonprod"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"InverseRules": [{
"Transitive": true,
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/inverse/lib"
]
}]
}
2 changes: 2 additions & 0 deletions examples/import-boss/tests/inverse/lib/nonprod/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// nonprod is non-production code that should not be linked into any outside package.
package nonprod
Original file line number Diff line number Diff line change
@@ -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"
]
}]
}
1 change: 1 addition & 0 deletions examples/import-boss/tests/inverse/lib/private/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package private
1 change: 1 addition & 0 deletions examples/import-boss/tests/inverse/lib/public/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package public
6 changes: 6 additions & 0 deletions examples/import-boss/tests/inverse/lib/quarantine/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
11 changes: 11 additions & 0 deletions examples/import-boss/tests/rules/a/.import-restrictions
Original file line number Diff line number Diff line change
@@ -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"
]
}]
}
5 changes: 5 additions & 0 deletions examples/import-boss/tests/rules/a/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a

import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/b"
)
11 changes: 11 additions & 0 deletions examples/import-boss/tests/rules/b/.import-restrictions
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
""
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}
6 changes: 6 additions & 0 deletions examples/import-boss/tests/rules/b/doc.go
Original file line number Diff line number Diff line change
@@ -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"
)
1 change: 1 addition & 0 deletions examples/import-boss/tests/rules/c/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package c
10 changes: 10 additions & 0 deletions examples/import-boss/tests/rules/nested/.import-restrictions
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}
5 changes: 5 additions & 0 deletions examples/import-boss/tests/rules/nested/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nested

import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
],
"ForbiddenPrefixes": [
]
}]
}
5 changes: 5 additions & 0 deletions examples/import-boss/tests/rules/nested/nested/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nested

import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Rules": [{
"SelectorRegexp": "k8s[.]io/gengo",
"AllowedPrefixes": [
],
"ForbiddenPrefixes": [
"k8s.io/gengo/examples/import-boss/tests/rules/c"
]
}]
}
5 changes: 5 additions & 0 deletions examples/import-boss/tests/rules/nested/nested/nested/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nested

import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package inherit

import (
_ "k8s.io/gengo/examples/import-boss/tests/rules/c"
)

0 comments on commit 5c9e6c0

Please sign in to comment.