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

Add bash test target to run generate code before the test_util #72

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ generate:
sh -c "go generate"

test:
@go test -race -coverprofile=coverage.txt -covermode=atomic -v $(shell go list ./... | grep -v /vendor/)
@echo "Running Oscalkit test Utility"
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_HIGH-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_MODERATE-baseline_profile.xml
@sh test_util/RunTest.sh -p test_util/artifacts/NIST_SP-800-53_rev4_LOW-baseline_profile.xml
@echo "Running remaining tests"
@go test -race -coverprofile=coverage.txt -covermode=atomic -v $(shell go list ./... | grep -v "/vendor/\|/test_util/src")

build-docker:
docker image build --build-arg VERSION=$(VERSION) --build-arg BUILD=$(BUILD) --build-arg DATE=$(DATE) -t $(NAMESPACE)/$(REPO):$(VERSION)-$(BUILD) .
Expand Down
1 change: 0 additions & 1 deletion doc.go

This file was deleted.

21 changes: 0 additions & 21 deletions test/Readme.md

This file was deleted.

24 changes: 24 additions & 0 deletions test_util/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test

Test is a utility used for testing the go structures being generated by oscalkit from the profiles being provided.

Prerequisite
======

```
NOTE: The downloaded profile that needs to be tested should contain downloadable href links to catalogs and profiles. In case a relative path is provided, please download the linked catalogs or profiles in test_util/artifacts.
```

Run Test
========
The test can be run using `make test`, this will run the oscalkit `test_util` prior to the reamining tests.

Otherwise the test can be run using, `sh RunTest.sh -p <path to the downloaded profile to be tested>`

This will run `cli/main.go generate code` with the provided path and then run `test_util/src/*.go` with the provided path.

To run only the test without the `cli/main.go generate code` in case `output.go` already exists run:


`go run test_util/src/*.go -p <path to the downloaded profile to be tested>`

38 changes: 38 additions & 0 deletions test_util/RunTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

print_usage() {
printf "Usage: RunTest.sh [OPTION] \n\

OPTION:
-h Show this help
-p [Path to Profile] Execute the test, running oscalkit code generate with the provided profile
\n"
}

while getopts ':p:h' flag; do
case "${flag}" in
p) path=$OPTARG ;;
h) print_usage ;
exit ;;
*) "Invalid option: -$OPTARG" ;
print_usage ;
exit ;;
esac
done

if [ $OPTIND -eq 1 ]; then
print_usage
exit
fi

RED='\033[0;31m'
NC='\033[0m'
echo "Running test with profile path: $path"
go run cli/main.go generate code -p $path
if [ $? -eq 1 ]; then
echo "${RED}Generate code failed. Exiting test.${NC}"
rm output.go
exit
fi
go run test_util/src/*.go -p $path
rm output.go
Loading