
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
github.com/confusedimpa/testpackage
testpackage is a golang linter that makes you use a separate _test
package.
According to blackbox testing approach, you should not use unexported functions and methods from source code in tests.
Go allows to place tests in a separate package with suffix _test
.
For example, tests for store
package can be in the same package or in the package store_test
.
In the second case, you have to import the source code into tests so only exported things are available.
The linter reports if a test is in a package without suffix _test
.
If you really need to test unexported function, then put the test into file XXX_internal_test.go
.
The linter skips such files by default.
It also skips the file export_test.go
by default (see the last article below).
More detailed articles on this topic:
The best way is to use golangci-lint. It includes testpackage and a lot of other great linters.
See official site.
testpackage is disabled by default. To enable it, add the following to your .golangci.yml
:
linters:
enable:
testpackage
You can also change the regexp that is used to ignore files by the linter, and the list of packages that are allowed by default.
Here are the default values:
linters-settings:
testpackage:
skip-regexp: (export|internal)_test\.go
allow-packages:
- main
golangci-lint run
go install github.com/confusedimpa/testpackage
testpackage ./...
or
testpackage -skip-regexp="^$" ./...
testpackage -help
testpackage: linter that makes you use a separate _test package
Usage: testpackage [-flag] [package]
Flags:
-skip-regexp string
regexp pattern to skip file by name. To not skip files use -skip-regexp="^$" (default "(export|internal)_test\\.go")
-allow-packages string
comma separated list of packages that don't end with _test that tests are allowed to be in (default "main")
-V print version and exit
-c int
display offending line with this many lines of context (default -1)
-cpuprofile string
write CPU profile to this file
-debug string
debug flags, any subset of "fpstv"
-fix
apply all suggested fixes
-flags
print analyzer flags in JSON
-json
emit JSON output
-memprofile string
write memory profile to this file
-test
indicates whether test files should be analyzed, too (default true)
-trace string
write trace log to this file
main
package by default and add flag -allow-packages
to allow tests without _test
suffix (thanks G-Rath)main.go
to run the analyzerFAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.