Documentation
¶
Overview ¶
Package testlicense provides the function to check a license file.
usage: In your `some_test.go`, write a test code like below.
package yourpackage_test
import (
"testing"
"github.com/google/licensecheck"
"github.com/takumakei/go-testlicense"
)
func TestLicense(t *testing.T) {
testlicense.Test(t, licensecheck.MIT)
}
Index ¶
- Variables
- func AssertLicense(want licensecheck.Type, percent float64) error
- func AssertLicenseDir(dir DirnamesReader, want licensecheck.Type, percent float64) error
- func IsLicenseFilename(s string) bool
- func ReadLicense() (filename string, contents []byte, err error)
- func ReadLicenseDir(dir DirnamesReader) (filename string, contents []byte, err error)
- func Test(t *testing.T, want licensecheck.Type)
- func TestPercent(t *testing.T, want licensecheck.Type, percent float64)
- type DirnamesReader
Constants ¶
This section is empty.
Variables ¶
var Filenames = []string{
"COPYING",
"COPYING.md",
"COPYING.markdown",
"COPYING.txt",
"LICENCE",
"LICENCE.md",
"LICENCE.markdown",
"LICENCE.txt",
"LICENSE",
"LICENSE.md",
"LICENSE.markdown",
"LICENSE.txt",
"LICENSE-2.0.txt",
"LICENCE-2.0.txt",
"LICENSE-APACHE",
"LICENCE-APACHE",
"LICENSE-APACHE-2.0.txt",
"LICENCE-APACHE-2.0.txt",
"LICENSE-MIT",
"LICENCE-MIT",
"LICENSE.MIT",
"LICENCE.MIT",
"LICENSE.code",
"LICENCE.code",
"LICENSE.docs",
"LICENCE.docs",
"LICENSE.rst",
"LICENCE.rst",
"MIT-LICENSE",
"MIT-LICENCE",
"MIT-LICENSE.md",
"MIT-LICENCE.md",
"MIT-LICENSE.markdown",
"MIT-LICENCE.markdown",
"MIT-LICENSE.txt",
"MIT-LICENCE.txt",
"MIT_LICENSE",
"MIT_LICENCE",
"UNLICENSE",
"UNLICENCE",
}
Filenames for license.
https://pkg.go.dev/license-policy
> We currently use github.com/google/licensecheck for license detection, and > look for licenses in files with the following names: COPYING, COPYING.md, > COPYING.markdown, COPYING.txt, LICENCE, LICENCE.md, LICENCE.markdown, > LICENCE.txt, LICENSE, LICENSE.md, LICENSE.markdown, LICENSE.txt, > LICENSE-2.0.txt, LICENCE-2.0.txt, LICENSE-APACHE, LICENCE-APACHE, > LICENSE-APACHE-2.0.txt, LICENCE-APACHE-2.0.txt, LICENSE-MIT, LICENCE-MIT, > LICENSE.MIT, LICENCE.MIT, LICENSE.code, LICENCE.code, LICENSE.docs, > LICENCE.docs, LICENSE.rst, LICENCE.rst, MIT-LICENSE, MIT-LICENCE, > MIT-LICENSE.md, MIT-LICENCE.md, MIT-LICENSE.markdown, MIT-LICENCE.markdown, > MIT-LICENSE.txt, MIT-LICENCE.txt, MIT_LICENSE, MIT_LICENCE, UNLICENSE, > UNLICENCE. The match is case-insensitive.
Functions ¶
func AssertLicense ¶
func AssertLicense(want licensecheck.Type, percent float64) error
AssertLicense returns err != nil if the license in the current directory does not match want or percentage is less than percent.
func AssertLicenseDir ¶
func AssertLicenseDir(dir DirnamesReader, want licensecheck.Type, percent float64) error
AssertLicenseDir returns err != nil if the license in the dir does not match want or percentage is less than percent.
func IsLicenseFilename ¶
IsLicenseFilename returns true if the string s matches any one of license filenames.
func ReadLicense ¶
ReadLicenseDir searchs the license file in the current dir and returns the filename and the contents.
func ReadLicenseDir ¶
func ReadLicenseDir(dir DirnamesReader) (filename string, contents []byte, err error)
ReadLicenseDir searchs the license file in the dir and returns the filename and the contents.
func Test ¶
func Test(t *testing.T, want licensecheck.Type)
TestPercent calls t.Fatal(err) if no license file is found or percentage is less than 90%.
func TestPercent ¶
func TestPercent(t *testing.T, want licensecheck.Type, percent float64)
TestPercent calls t.Fatal(err) if no license file is found or percentage is less than percent.