-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from opencontrol/add-workspace
Create Workspace interface and make LocalWorkspace private
- Loading branch information
Showing
19 changed files
with
255 additions
and
178 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,26 @@ | ||
package common | ||
|
||
// Verification struct holds data for a specific component and verification | ||
// This is an internal data structure that helps map standards and controls to components | ||
type Verification struct { | ||
ComponentKey string | ||
SatisfiesData Satisfies | ||
} | ||
|
||
// Verifications is a slice of type Verifications | ||
type Verifications []Verification | ||
|
||
// Len returns the length of the GeneralReferences slice | ||
func (slice Verifications) Len() int { | ||
return len(slice) | ||
} | ||
|
||
// Less returns true if a GeneralReference is less than another reference | ||
func (slice Verifications) Less(i, j int) bool { | ||
return slice[i].ComponentKey < slice[j].ComponentKey | ||
} | ||
|
||
// Swap swaps the two GeneralReferences | ||
func (slice Verifications) Swap(i, j int) { | ||
slice[i], slice[j] = slice[j], slice[i] | ||
} |
This file contains 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,57 @@ | ||
package common_test | ||
|
||
import ( | ||
"github.com/opencontrol/compliance-masonry/lib/common" | ||
"testing" | ||
) | ||
|
||
type verificationsLenTest struct { | ||
verifications common.Verifications | ||
expectedLength int | ||
} | ||
|
||
type verificationsLessTest struct { | ||
verifications common.Verifications | ||
leftIsLess bool | ||
} | ||
|
||
var verificationsLenTests = []verificationsLenTest{ | ||
// Check that the number of verifications stored is 0 | ||
{common.Verifications{}, 0}, | ||
// Check that the number of verifications stored is 1 | ||
{common.Verifications{common.Verification{}}, 1}, | ||
// Check that the number of verifications stored is 2 | ||
{common.Verifications{common.Verification{}, common.Verification{}}, 2}, | ||
} | ||
|
||
func TestVerificationsLen(t *testing.T) { | ||
for _, example := range verificationsLenTests { | ||
actualLength := example.verifications.Len() | ||
// Check that the number of verifications is the expected number | ||
if example.expectedLength != actualLength { | ||
t.Errorf("Expected %d, Actual: %d", example.expectedLength, actualLength) | ||
} | ||
} | ||
} | ||
|
||
var verificationsLessTests = []verificationsLessTest{ | ||
// Check that the left verification is less by comparing a number and letter | ||
{common.Verifications{common.Verification{ComponentKey: "1", SatisfiesData: nil}, common.Verification{ComponentKey: "2", SatisfiesData: nil}}, true}, | ||
// Check that the left verification is not less by comparing two letters | ||
{common.Verifications{common.Verification{ComponentKey: "a", SatisfiesData: nil}, common.Verification{ComponentKey: "a", SatisfiesData: nil}}, false}, | ||
// Check that the left verification is not less by comparing the same letter | ||
{common.Verifications{common.Verification{ComponentKey: "a", SatisfiesData: nil}, common.Verification{ComponentKey: "2", SatisfiesData: nil}}, false}, | ||
// Check that the left verification is not less by comparing two numbers | ||
{common.Verifications{common.Verification{ComponentKey: "2", SatisfiesData: nil}, common.Verification{ComponentKey: "1", SatisfiesData: nil}}, false}, | ||
// Check that the left verification is not less by comparing two numbers | ||
} | ||
|
||
func TestVerificationsLess(t *testing.T) { | ||
for _, example := range verificationsLessTests { | ||
actualLeftIsLess := example.verifications.Less(0, 1) | ||
// Check that the verification on the left is less as expected | ||
if example.leftIsLess != actualLeftIsLess { | ||
t.Errorf("Expected %t, Actual: %t", actualLeftIsLess, actualLeftIsLess) | ||
} | ||
} | ||
} |
This file contains 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,14 @@ | ||
package common | ||
|
||
// Workspace represents all the information such as components, standards, and certification as well as | ||
// the result information such as the justifications. | ||
type Workspace interface { | ||
LoadComponents(string) []error | ||
LoadStandards(string) []error | ||
LoadCertification(string) error | ||
GetCertification() Certification | ||
GetAllComponents() []Component | ||
GetComponent(componentKey string) (Component, bool) | ||
GetStandard(standardKey string) (Standard, bool) | ||
GetAllVerificationsWith(standardKey string, controlKey string) Verifications | ||
} |
This file contains 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 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
Oops, something went wrong.