Skip to content

Commit

Permalink
Merge pull request #8 from boyter/AddtionalTests
Browse files Browse the repository at this point in the history
Add integration tests
  • Loading branch information
boyter authored Feb 12, 2018
2 parents 2dd25e5 + 7980a11 commit 3f00e91
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 56 deletions.
56 changes: 4 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions parsers/guesser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ 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.0
var confidence = 0.85
var Confidence = ""
var PossibleLicenceFiles = ""
var DirFilePaths = []string{}
Expand All @@ -33,7 +33,7 @@ var DeepGuess = ""
var Format = ""
var FileOutput = ""
var ExtentionBlacklist = ""
var maxSize = 0
var maxSize = 50000
var MaxSize = ""
var DocumentName = ""
var PackageName = ""
Expand Down
36 changes: 36 additions & 0 deletions parsers/guesser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
2 changes: 1 addition & 1 deletion scripts/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3f00e91

Please sign in to comment.