Skip to content

No internal package use in tests#1175

Draft
TBBle wants to merge 3 commits intomicrosoft:mainfrom
TBBle:no-internal-package-use-in-tests
Draft

No internal package use in tests#1175
TBBle wants to merge 3 commits intomicrosoft:mainfrom
TBBle:no-internal-package-use-in-tests

Conversation

@TBBle
Copy link
Copy Markdown
Contributor

@TBBle TBBle commented Sep 24, 2021

Based on a comment I made earlier in #1073, I had a look at it would take to enforce a "No imports from internal in tests" policy.

A couple of easy, self-contained packages to make public fell out, but then the next thing I wanted to make public was internal/cmd, and it exposes a couple of types in its APIs from internal/cow and internal/uvm, and the dependency graph explodes at that point, even before I looked at test/functional/wcow_test.go which pulls 10 different packages from internal plus hcsshim itself, probably because of

// Has testing for Windows containers using both the older hcsshim methods,
// and the newer hcsoci methods. Does the same thing in six different ways:
// - hcsshim/argon
// - hcsshim/xenon
// - hcsoci/argon v1
// - hcsoci/xenon v1
// - hcsoci/argon v2
// - hcsoci/xenon v2

which leaps-out as a super-code smell if it's testing old and new interfaces, and the entire "new" interface is not public.

So I'm posting this for direction/consideration/ideation:

@TBBle TBBle force-pushed the no-internal-package-use-in-tests branch 3 times, most recently from a54b0e5 to fbffeaa Compare November 27, 2021 10:59
@TBBle TBBle mentioned this pull request Nov 27, 2021
2 tasks
TBBle added 3 commits May 4, 2022 20:27
An idea mentioned in-passing in microsoft#1073, this would ensure that tests can
be looked at as usage examples, which use of internal APIs prevents.

vendor/ and internal/ are excluded, the former because we only care
about direct dependencies, and the latter so that if tests are done that
depend on an unpublished API, it's possible _and_ explicit.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
Some alternative approaches:
* Move the relevant tests to tests/internal to make it clear it's
  testing internal stuff.
* Restructure the four tests to use a compiled shimdiag.exe or
  host-provided hcsdiag.exe instead, assuming the latter is equivalent.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
@TBBle TBBle force-pushed the no-internal-package-use-in-tests branch from fbffeaa to df1b28a Compare May 4, 2022 10:34
@TBBle
Copy link
Copy Markdown
Contributor Author

TBBle commented May 6, 2023

If I or someone else ever come back to this, I saw a neat trick in the Go source itself, of having an _test.go-suffixed file that only exports internal symbols for use in tests. It might not help here, but did remind me of this experiment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant