-
Notifications
You must be signed in to change notification settings - Fork 62
Cross Platform Testing TestBuilder2_1CanBuildPackageSection #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18b10af
Cross Platform Testing TestBuilder2_1CanBuildPackageSection
CatalinStratu 4ba81f5
Cross Platform Testing TestBuilder2_1CanBuildPackageSection
CatalinStratu 437743f
Coments
CatalinStratu 3f6c4b4
Symbolic link
CatalinStratu c0e3777
Symbolic link fixes
CatalinStratu 2b6c853
Merge branch 'spdx:main' into main
CatalinStratu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
builder/builder2v1/build_package_test.go → ...er/builder2v1/build_package_linux_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
package builder2v1 | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/spdx/tools-golang/spdx" | ||
) | ||
|
||
// Verify if file exists | ||
func fileExists(path string) bool { | ||
_, err := os.Stat(path) | ||
return !os.IsNotExist(err) | ||
} | ||
|
||
// ===== Package section builder tests ===== | ||
func TestBuilder2_1CanBuildPackageSection(t *testing.T) { | ||
packageName := "project1" | ||
dirRoot := "../../testdata/project1_windows/" | ||
|
||
// check if the file exists | ||
if !fileExists("../../testdata/project1_windows/symbolic-link") { | ||
// create a new symbolic link | ||
err := os.Symlink("../../testdata/project1_windows/file3.testdata.txt", "../../testdata/project1_windows/symbolic-link") | ||
if err != nil { | ||
t.Errorf("Do not have administrator rights : %v", err) | ||
os.Exit(1) | ||
} | ||
} | ||
wantVerificationCode := "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b" | ||
|
||
pkg, err := BuildPackageSection2_1(packageName, dirRoot, nil) | ||
if err != nil { | ||
t.Fatalf("expected nil error, got %v", err) | ||
} | ||
|
||
if pkg == nil { | ||
t.Fatalf("expected non-nil Package, got nil") | ||
} | ||
if pkg.PackageName != "project1" { | ||
t.Errorf("expected %v, got %v", "project1", pkg.PackageName) | ||
} | ||
if pkg.PackageSPDXIdentifier != spdx.ElementID("Package-project1") { | ||
t.Errorf("expected %v, got %v", "Package-project1", pkg.PackageSPDXIdentifier) | ||
} | ||
if pkg.PackageDownloadLocation != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", pkg.PackageDownloadLocation) | ||
} | ||
if pkg.FilesAnalyzed != true { | ||
t.Errorf("expected %v, got %v", true, pkg.FilesAnalyzed) | ||
} | ||
if pkg.IsFilesAnalyzedTagPresent != true { | ||
t.Errorf("expected %v, got %v", true, pkg.IsFilesAnalyzedTagPresent) | ||
} | ||
if pkg.PackageVerificationCode != wantVerificationCode { | ||
t.Errorf("expected %v, got %v", wantVerificationCode, pkg.PackageVerificationCode) | ||
} | ||
if pkg.PackageLicenseConcluded != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", pkg.PackageLicenseConcluded) | ||
} | ||
if len(pkg.PackageLicenseInfoFromFiles) != 0 { | ||
t.Errorf("expected %v, got %v", 0, len(pkg.PackageLicenseInfoFromFiles)) | ||
} | ||
if pkg.PackageLicenseDeclared != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", pkg.PackageLicenseDeclared) | ||
} | ||
if pkg.PackageCopyrightText != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", pkg.PackageCopyrightText) | ||
} | ||
|
||
// and make sure we got the right number of files, and check the first one | ||
if pkg.Files == nil { | ||
t.Fatalf("expected non-nil pkg.Files, got nil") | ||
} | ||
if len(pkg.Files) != 5 { | ||
t.Fatalf("expected %d, got %d", 5, len(pkg.Files)) | ||
} | ||
fileEmpty := pkg.Files[spdx.ElementID("File0")] | ||
if fileEmpty == nil { | ||
t.Fatalf("expected non-nil file, got nil") | ||
} | ||
if fileEmpty.FileName != "emptyfile.testdata.txt" { | ||
t.Errorf("expected %v, got %v", "emptyfile.testdata.txt", fileEmpty.FileName) | ||
} | ||
if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") { | ||
t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier) | ||
} | ||
if fileEmpty.FileChecksumSHA1 != "da39a3ee5e6b4b0d3255bfef95601890afd80709" { | ||
t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", fileEmpty.FileChecksumSHA1) | ||
} | ||
if fileEmpty.FileChecksumSHA256 != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" { | ||
t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", fileEmpty.FileChecksumSHA256) | ||
} | ||
if fileEmpty.FileChecksumMD5 != "d41d8cd98f00b204e9800998ecf8427e" { | ||
t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", fileEmpty.FileChecksumMD5) | ||
} | ||
if fileEmpty.LicenseConcluded != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseConcluded) | ||
} | ||
if len(fileEmpty.LicenseInfoInFile) != 1 { | ||
t.Errorf("expected %v, got %v", 1, len(fileEmpty.LicenseInfoInFile)) | ||
} else { | ||
if fileEmpty.LicenseInfoInFile[0] != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.LicenseInfoInFile[0]) | ||
} | ||
} | ||
if fileEmpty.FileCopyrightText != "NOASSERTION" { | ||
t.Errorf("expected %v, got %v", "NOASSERTION", fileEmpty.FileCopyrightText) | ||
} | ||
|
||
// Remove symbolic link after test | ||
err = os.Remove("../../testdata/project1_windows/symbolic-link") | ||
if err != nil { | ||
t.Errorf("the file could not be deleted : %v", err) | ||
} | ||
} | ||
|
||
func TestBuilder2_1CanIgnoreFiles(t *testing.T) { | ||
packageName := "project3" | ||
dirRoot := "../../testdata/project3/" | ||
pathsIgnored := []string{ | ||
"**/ignoredir/", | ||
"/excludedir/", | ||
"**/ignorefile.txt", | ||
"/alsoEXCLUDEthis.txt", | ||
} | ||
pkg, err := BuildPackageSection2_1(packageName, dirRoot, pathsIgnored) | ||
if err != nil { | ||
t.Fatalf("expected nil error, got %v", err) | ||
} | ||
|
||
// make sure we got the right files | ||
if pkg.Files == nil { | ||
t.Fatalf("expected non-nil pkg.Files, got nil") | ||
} | ||
if len(pkg.Files) != 5 { | ||
t.Fatalf("expected %d, got %d", 5, len(pkg.Files)) | ||
} | ||
|
||
want := "./dontscan.txt" | ||
got := pkg.Files[spdx.ElementID("File0")].FileName | ||
if want != got { | ||
t.Errorf("expected %v, got %v", want, got) | ||
} | ||
|
||
want = "./keep/keep.txt" | ||
got = pkg.Files[spdx.ElementID("File1")].FileName | ||
if want != got { | ||
t.Errorf("expected %v, got %v", want, got) | ||
} | ||
|
||
want = "./keep.txt" | ||
got = pkg.Files[spdx.ElementID("File2")].FileName | ||
if want != got { | ||
t.Errorf("expected %v, got %v", want, got) | ||
} | ||
|
||
want = "./subdir/keep/dontscan.txt" | ||
got = pkg.Files[spdx.ElementID("File3")].FileName | ||
if want != got { | ||
t.Errorf("expected %v, got %v", want, got) | ||
} | ||
|
||
want = "./subdir/keep/keep.txt" | ||
got = pkg.Files[spdx.ElementID("File4")].FileName | ||
if want != got { | ||
t.Errorf("expected %v, got %v", want, got) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
file3.testdata.txt | ||
../../testdata/project1_windows/file3.testdata.txt |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
arbitrary content for testing purposes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file contains some sort of documentation or whatever |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
blah blah blah | ||
this file has text in it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
|
||
somebody was kind enough to stick an spdx short-form ID in here |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"./"