File: main_test.go

package info (click to toggle)
golang-github-go-enry-go-license-detector 4.3.0%2Bgit20221007.a3a1cc6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,068 kB
  • sloc: makefile: 25
file content (39 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"bytes"
	"encoding/json"
	"testing"

	"github.com/go-enry/go-license-detector/v4/licensedb"
	"github.com/stretchr/testify/assert"
)

func TestCmdMain(t *testing.T) {
	buffer := &bytes.Buffer{}
	detect([]string{"../..", "."}, "json", buffer)
	var r []licensedb.Result
	err := json.Unmarshal(buffer.Bytes(), &r)
	assert.NoError(t, err)
	assert.Len(t, r, 2)
	assert.Equal(t, "../..", r[0].Arg)
	assert.Equal(t, ".", r[1].Arg)
	assert.Len(t, r[0].Matches, 4)
	assert.Len(t, r[1].Matches, 0)
	assert.Equal(t, "", r[0].ErrStr)
	assert.Equal(t, "no license file was found", r[1].ErrStr)
	assert.Equal(t, "Apache-2.0", r[0].Matches[0].License)
	assert.InDelta(t, 0.9877, r[0].Matches[0].Confidence, 0.002)
	assert.Equal(t, "ECL-2.0", r[0].Matches[1].License)
	assert.InDelta(t, 0.9047, r[0].Matches[1].Confidence, 0.002)
	buffer.Reset()
	detect([]string{"../..", "."}, "text", buffer)
	assert.Equal(t, `../..
	99%	Apache-2.0
	90%	ECL-2.0
	81%	SHL-0.51
	81%	SHL-0.5
.
	no license file was found
`, buffer.String())
}