From 88c3c0a021132f8eee18302b785f2fe8eef63025 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 12 Feb 2018 14:03:55 +1100 Subject: [PATCH 1/3] Format readme slightly --- README.md | 56 ++++--------------------------------------------------- 1 file changed, 4 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 1ecbe2d..5dea050 100644 --- a/README.md +++ b/README.md @@ -145,55 +145,7 @@ zip -r9 lc-1.0.0-x86_64-pc-windows.zip lc.exe && zip -r9 lc-1.0.0-x86_64-unknown ### TODO -Add error handling for all the file operations and just in general. Most are currently ignored - -Add logic to guess the file type for SPDX value FileType - -Add addtional unit and integration tests - -Investigate using "github.com/gosuri/uitable" for formatting https://github.com/gosuri/uitable - -Investigate using zlib compression for databases as per the below - -``` -package main - -import ( - "bytes" - "compress/zlib" - "fmt" - "io" - "io/ioutil" -) - -func readFile(filepath string) []byte { - // TODO only read as deep into the file as we need - bytes, err := ioutil.ReadFile(filepath) - - if err != nil { - fmt.Print(err) - } - - return bytes -} - -func main() { - - contents := readFile("database_keywords.json") - fmt.Println(len(contents)) - - var in bytes.Buffer - b := []byte(contents) - w := zlib.NewWriter(&in) - w.Write(b) - w.Close() - - fmt.Println(len(in.String())) - - var out bytes.Buffer - r, _ := zlib.NewReader(&in) - io.Copy(&out, r) - fmt.Println(len(out.String())) - // fmt.Println(len(out.String())) -} -``` +* Add error handling for all the file operations and just in general. Most are currently ignored +* Add logic to guess the file type for SPDX value FileType +* Add addtional unit and integration tests +* Investigate using "github.com/gosuri/uitable" for formatting https://github.com/gosuri/uitable \ No newline at end of file From 55dc7ffc1ea228c0ca74f5b2aa170f1b27027775 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 12 Feb 2018 14:36:21 +1100 Subject: [PATCH 2/3] Update to have some integration tests --- parsers/guesser.go | 4 ++-- parsers/guesser_test.go | 36 ++++++++++++++++++++++++++++++++++++ scripts/include.go | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/parsers/guesser.go b/parsers/guesser.go index b016f80..3871208 100644 --- a/parsers/guesser.go +++ b/parsers/guesser.go @@ -23,7 +23,7 @@ var ToolName = "licensechecker" var ToolVersion = "1.0.2" // Set by user as command line arguments -var confidence = 0.0 +var confidence = 0.85 var Confidence = "" var PossibleLicenceFiles = "" var DirFilePaths = []string{} @@ -33,7 +33,7 @@ var DeepGuess = "" var Format = "" var FileOutput = "" var ExtentionBlacklist = "" -var maxSize = 0 +var maxSize = 50000 var MaxSize = "" var DocumentName = "" var PackageName = "" diff --git a/parsers/guesser_test.go b/parsers/guesser_test.go index 824b16f..5e9ca51 100644 --- a/parsers/guesser_test.go +++ b/parsers/guesser_test.go @@ -31,3 +31,39 @@ func TestLoadDatabase(t *testing.T) { t.Errorf("Expected database to not be empty") } } + +func TestWalkDirectory(t *testing.T) { + actual := walkDirectory("../examples/identifier/", [][]LicenseMatch{}) + + if len(actual) != 3 { + t.Errorf("Expected 3 results for directory") + } +} + +func TestProcessFile(t *testing.T) { + actual := processFile("../examples/identifier/", "has_identifier.py", []LicenseMatch{}) + + if actual.Md5Hash != "0ad2e6786423fa6933a49ae4f97ae79e" { + t.Errorf("Expected MD5 to match") + } + + if actual.Sha1Hash != "64904ca8a945009f95734d19198aaacd5e2db959" { + t.Errorf("Expected SHA1 to match") + } + + if actual.Sha256Hash != "bf201f35c6a8504b4d956b4403ff5a7fef490889d5166a34f01b653e4ce08a06" { + t.Errorf("Expected SHA256 to match") + } + + if len(actual.LicenseIdentified) != 2 { + t.Errorf("Expected 2 identified licenses") + } + + if actual.LicenseIdentified[0].LicenseId != "GPL-2.0" { + t.Errorf("Expected license not identified") + } + + if actual.LicenseIdentified[1].LicenseId != "GPL-3.0+" { + t.Errorf("Expected license not identified") + } +} diff --git a/scripts/include.go b/scripts/include.go index 45468e7..3d642a0 100644 --- a/scripts/include.go +++ b/scripts/include.go @@ -22,7 +22,7 @@ func readFile(filepath string) []byte { } // Reads all .json files in the current folder -// and encodes them as strings literals in textfiles.go +// and encodes them as strings literals in constants.go func main() { files, _ := ioutil.ReadDir(".") out, _ := os.Create("./parsers/constants.go") From 7980a11816f098e493e8e889f98f4eb73f93a3e9 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 12 Feb 2018 14:42:04 +1100 Subject: [PATCH 3/3] Rename version to 1.1.1 so that it reflects in the next build --- parsers/guesser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsers/guesser.go b/parsers/guesser.go index 3871208..1f55738 100644 --- a/parsers/guesser.go +++ b/parsers/guesser.go @@ -20,7 +20,7 @@ import ( // Shared all over the place var ToolName = "licensechecker" -var ToolVersion = "1.0.2" +var ToolVersion = "1.1.1" // Set by user as command line arguments var confidence = 0.85