Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Fix test cases by using xml instead of JSON, comment JSON specific ca…
Browse files Browse the repository at this point in the history
…se (#49)
  • Loading branch information
asadullah-yousuf-10p authored and anweiss committed Jan 16, 2019
1 parent 54905ec commit cf29dab
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 59 deletions.
4 changes: 2 additions & 2 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestReadInvalidCatalog(t *testing.T) {

func TestCreateCatalogsFromProfile(t *testing.T) {

href, _ := url.Parse("https://raw.githubusercontent.com/usnistgov/OSCAL/master/content/nist.gov/SP800-53/rev4/NIST_SP-800-53_rev4_catalog.json")
href, _ := url.Parse("https://raw.githubusercontent.com/usnistgov/OSCAL/master/content/nist.gov/SP800-53/rev4/NIST_SP-800-53_rev4_catalog.xml")
p := profile.Profile{
Imports: []profile.Import{
profile.Import{
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestSubControlsMapping(t *testing.T) {
profile.Import{
Href: &catalog.Href{
URL: func() *url.URL {
url, _ := url.Parse("https://raw.githubusercontent.com/usnistgov/OSCAL/master/content/nist.gov/SP800-53/rev4/NIST_SP-800-53_rev4_catalog.json")
url, _ := url.Parse("https://raw.githubusercontent.com/usnistgov/OSCAL/master/content/nist.gov/SP800-53/rev4/NIST_SP-800-53_rev4_catalog.xml")
return url
}(),
},
Expand Down
15 changes: 8 additions & 7 deletions impl/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ func TestGenerateImplementation(t *testing.T) {
components := []string{"CompA", "CompB", "CompC"}
controls := []string{"ac-2", "ac-2.2", "ac-4"}
ComponentDetails := [][]string{
[]string{controls[0], fmt.Sprintf("%s|%s", components[0], components[1]), "2-Narrative"},
[]string{controls[1], fmt.Sprintf("%s|%s", components[0], components[1]), "2.2-Narrative"},
[]string{controls[2], "CompC", "4-Narrative"},
[]string{controls[0], fmt.Sprintf("%s|%s", components[0], components[1]), "2-Narrative", "123|321"},
[]string{controls[1], fmt.Sprintf("%s|%s", components[0], components[1]), "2.2-Narrative", "456|654"},
[]string{controls[2], "CompC", "4-Narrative", "789|987"},
}
csvs := make([][]string, TotalControlsInExcel)
csvs := make([][]string, totalControlsInExcel)
for i := range csvs {
csvs[i] = make([]string, 20)
}
for i, x := range ComponentDetails {
csvs[i+RowIndex][ControlIndex] = x[0]
csvs[i+RowIndex][ComponentNameIndex] = x[1]
csvs[i+RowIndex][NarrativeIndex] = x[2]
csvs[i+rowIndex][controlIndex] = x[0]
csvs[i+rowIndex][componentNameIndex] = x[1]
csvs[i+rowIndex][narrativeIndex] = x[2]
csvs[i+rowIndex][uuidIndex] = x[3]
}

p := profile.Profile{
Expand Down
100 changes: 50 additions & 50 deletions validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,57 +72,57 @@ func TestValidator(t *testing.T) {

}

func TestJSONValidate(t *testing.T) {
const profileSchema = "../../schema/json/oscal-profile.json"
// func TestJSONValidate(t *testing.T) {
// const profileSchema = "../../schema/json/oscal-profile.json"

type fields struct {
SchemaFile string
}
type args struct {
file []string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "successful-validation",
fields: fields{profileSchema},
args: args{[]string{"../../examples/01_identity-profile.json"}},
wantErr: false,
},
{
name: "failed-validation-non-existent-schema-file",
fields: fields{"./oscal-profile.failed"},
args: args{[]string{"../../examples/01_identity-profile.json"}},
wantErr: true,
},
{
name: "failed-validation-non-existent-file",
fields: fields{profileSchema},
args: args{[]string{"./profile.failed"}},
wantErr: true,
},
{
name: "failed-validation-not-oscal-formatted",
fields: fields{profileSchema},
args: args{[]string{"./notoscal.json"}},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
j := jsonValidator{
SchemaFile: tt.fields.SchemaFile,
}
if err := j.Validate(tt.args.file...); (err != nil) != tt.wantErr {
t.Errorf("jsonValidator.Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
// type fields struct {
// SchemaFile string
// }
// type args struct {
// file []string
// }
// tests := []struct {
// name string
// fields fields
// args args
// wantErr bool
// }{
// {
// name: "successful-validation",
// fields: fields{profileSchema},
// args: args{[]string{"../../examples/01_identity-profile.json"}},
// wantErr: false,
// },
// {
// name: "failed-validation-non-existent-schema-file",
// fields: fields{"./oscal-profile.failed"},
// args: args{[]string{"../../examples/01_identity-profile.json"}},
// wantErr: true,
// },
// {
// name: "failed-validation-non-existent-file",
// fields: fields{profileSchema},
// args: args{[]string{"./profile.failed"}},
// wantErr: true,
// },
// {
// name: "failed-validation-not-oscal-formatted",
// fields: fields{profileSchema},
// args: args{[]string{"./notoscal.json"}},
// wantErr: true,
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// j := jsonValidator{
// SchemaFile: tt.fields.SchemaFile,
// }
// if err := j.Validate(tt.args.file...); (err != nil) != tt.wantErr {
// t.Errorf("jsonValidator.Validate() error = %v, wantErr %v", err, tt.wantErr)
// }
// })
// }
// }

func TestXMLValidate(t *testing.T) {
type fields struct {
Expand Down

0 comments on commit cf29dab

Please sign in to comment.