File: dataset_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 (47 lines) | stat: -rw-r--r-- 1,175 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
40
41
42
43
44
45
46
47
package licensedb

import (
	"fmt"
	"os"
	"sync"
	"testing"

	"github.com/go-enry/go-license-detector/v4/licensedb/api"
	"github.com/go-enry/go-license-detector/v4/licensedb/filer"

	"github.com/stretchr/testify/assert"
)

func TestDataset(t *testing.T) {
	rootFiler, err := filer.FromZIP("dataset.zip")
	assert.Nil(t, err)
	defer rootFiler.Close()
	projects, err := rootFiler.ReadDir("")
	assert.Nil(t, err)
	licenses := map[string]map[string]api.Match{}
	mutex := sync.Mutex{}
	wg := sync.WaitGroup{}
	wg.Add(len(projects))
	for _, project := range projects {
		go func(project filer.File) {
			defer wg.Done()
			myLicenses, _ := Detect(filer.NestFiler(rootFiler, project.Name))
			if len(myLicenses) > 0 {
				mutex.Lock()
				licenses[project.Name] = myLicenses
				mutex.Unlock()
			}
		}(project)
	}
	wg.Wait()
	assert.True(t, len(licenses) >= 893)
	// the rest len(projects) - 902 do not contain any license information
	fmt.Printf("%d %d %d%%\n", len(licenses), 902, (100*len(licenses))/902)
	if os.Getenv("LICENSE_TEST_DEBUG") != "" {
		for _, project := range projects {
			if _, exists := licenses[project.Name]; !exists {
				println(project.Name)
			}
		}
	}
}