testlicense

package module
v0.0.0-...-fcbaa9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2020 License: MIT Imports: 7 Imported by: 0

README

go-testlicense

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)
}

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

Constants

This section is empty.

Variables

View Source
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

func IsLicenseFilename(s string) bool

IsLicenseFilename returns true if the string s matches any one of license filenames.

func ReadLicense

func ReadLicense() (filename string, contents []byte, err error)

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.

Types

type DirnamesReader

type DirnamesReader interface {
	Readdirnames(int) ([]string, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL