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

Commit

Permalink
Add part addition and traverse import chain
Browse files Browse the repository at this point in the history
  • Loading branch information
minhaj10p committed Jan 19, 2019
1 parent 9fc5e8b commit c9cc98e
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 75 deletions.
148 changes: 117 additions & 31 deletions generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"net/url"
"testing"

"github.com/davecgh/go-spew/spew"

"github.com/docker/oscalkit/types/oscal/catalog"
"github.com/docker/oscalkit/types/oscal/profile"
)
Expand Down Expand Up @@ -155,8 +153,8 @@ func TestCreateCatalogsFromProfileWithBadHref(t *testing.T) {
},
}
catalogs, err := CreateCatalogsFromProfile(&p)
if err != nil {
t.Error("error should be nil")
if err == nil {
t.Error("error should not be nil")
}
if len(catalogs) > 0 {
t.Error("nothing should be parsed due to bad url")
Expand Down Expand Up @@ -213,28 +211,18 @@ func TestGetCatalogInvalidFilePath(t *testing.T) {
}
}

func failTest(err error, t *testing.T) {
if err != nil {
t.Error(t)
}
}

func TestAddPartInCatalog(t *testing.T) {

alt := []profile.Alter{
profile.Alter{
func TestProcessAdditionWithSameClass(t *testing.T) {
partID := "ac-10_prt"
class := "guidance"
alters := []profile.Alter{
{
ControlId: "ac-10",
Additions: []profile.Add{
profile.Add{
Parts: []catalog.Part{
catalog.Part{
Id: "ac-10_prm",
Class: "guidance",
Title: "parent prm guidance",
},
catalog.Part{
Id: "ac-2_prm3",
Class: "whatever",
Id: partID,
Class: class,
},
},
},
Expand All @@ -246,39 +234,137 @@ func TestAddPartInCatalog(t *testing.T) {
profile.Add{
Parts: []catalog.Part{
catalog.Part{
Id: "ac-10_obj",
Class: "yolo",
Id: partID,
Class: class,
},
},
},
},
},
}

cat := catalog.Catalog{
c := catalog.Catalog{
Groups: []catalog.Group{
catalog.Group{
Controls: []catalog.Control{
catalog.Control{
Id: "ac-10",
Parts: []catalog.Part{
catalog.Part{
Id: partID,
Class: class,
},
},
Subcontrols: []catalog.Subcontrol{
catalog.Subcontrol{
Id: "ac-10.1",
Parts: []catalog.Part{},
Id: "ac-10.1",
Parts: []catalog.Part{
catalog.Part{
Id: partID,
Class: class,
},
},
},
},
},
},
},
},
}

o := ProcessAlteration(alters, &c)
for _, g := range o.Groups {
for _, c := range g.Controls {
for i := range c.Parts {
expected := fmt.Sprintf("%s_%d", partID, i+1)
if c.Parts[i].Id != expected {
t.Errorf("%s and %s are not identical", c.Parts[i].Id, expected)
return
}
}
for i, sc := range c.Subcontrols {
expected := fmt.Sprintf("%s_%d", partID, i+1)
if sc.Parts[i].Id != expected {
t.Errorf("%s and %s are not identical", sc.Parts[i].Id, expected)
return
}
}
}
}
}

func TestProcessAdditionWithDifferentPartClass(t *testing.T) {

ctrlID := "ac-10"
subctrlID := "ac-10.1"
partID := "ac-10_stmt.a"

alters := []profile.Alter{
profile.Alter{
ControlId: ctrlID,
Additions: []profile.Add{
profile.Add{
Parts: []catalog.Part{
catalog.Part{
Id: partID,
Class: "c1",
},
},
},
},
},
profile.Alter{
SubcontrolId: subctrlID,
Additions: []profile.Add{
profile.Add{
Parts: []catalog.Part{
catalog.Part{
Id: partID,
Class: "c2",
},
},
},
},
},
}
c := catalog.Catalog{
Groups: []catalog.Group{
catalog.Group{
Controls: []catalog.Control{
catalog.Control{
Id: ctrlID,
Parts: []catalog.Part{
catalog.Part{
Id: "ac_10_prm",
Class: "guidance",
Title: "sdfsdfsd",
Id: partID,
Class: "c3",
},
},
Subcontrols: []catalog.Subcontrol{
catalog.Subcontrol{
Id: subctrlID,
Parts: []catalog.Part{
catalog.Part{
Id: partID,
Class: "c4",
},
},
},
},
},
},
},
},
}
o := ProcessAlteration(alters, &c)
if len(o.Groups[0].Controls[0].Parts) != 2 {
t.Error("parts for controls not getting added properly")
}
if len(o.Groups[0].Controls[0].Subcontrols[0].Parts) != 2 {
t.Error("parts for sub-controls not getting added properly")
}

spew.Dump(AddPartInCatalog(alt, &cat))
}
func failTest(err error, t *testing.T) {
if err != nil {
t.Error(t)
}
}
Loading

0 comments on commit c9cc98e

Please sign in to comment.