-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oscal): create the multiModelValidate method for use in oscal co…
…nstructors and updated all relavant constructors
- Loading branch information
1 parent
96c3dfa
commit 8a5ecf3
Showing
8 changed files
with
324,926 additions
and
253,404 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package oscal | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/defenseunicorns/go-oscal/src/pkg/utils" | ||
"github.com/defenseunicorns/go-oscal/src/pkg/validation" | ||
) | ||
|
||
func multiModelValidate(data []byte) (err error) { | ||
jsonMap, err := utils.CoerceToJsonMap(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(jsonMap) == 0 { | ||
return errors.New("no models found") | ||
} | ||
|
||
for key, value := range jsonMap { | ||
jsonModel := make(map[string]interface{}) | ||
jsonModel[key] = value | ||
validator, err := validation.NewValidator(jsonModel) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = validator.Validate() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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,20 @@ | ||
package oscal | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestMultiValidate(t *testing.T) { | ||
multiModelData, err := os.ReadFile("../../../test/unit/common/oscal/multi-model.yaml") | ||
if err != nil { | ||
t.Fatalf("os.ReadFile failed: %v", err) | ||
} | ||
t.Run("Test Multi Validate", func(t *testing.T) { | ||
data := multiModelData | ||
err := multiModelValidate(data) | ||
if err != nil { | ||
t.Fatalf("multiModelValidate failed: %v", err) | ||
} | ||
}) | ||
} |
Oops, something went wrong.