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

Commit

Permalink
create new StructureTest instance for every file parse to avoid memor…
Browse files Browse the repository at this point in the history
…y overlap (#50)

* create new StructureTest instance for every file parse to avoid memory overlap

* add --no-pull and -h flags. gofmt

* fix --no-pull doc
  • Loading branch information
nkubala authored Nov 7, 2016
1 parent 186ff1e commit 07b3e9a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
26 changes: 25 additions & 1 deletion structure_tests/ext_run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh

VERBOSE=0
PULL=1
CMD_STRING=""
ENTRYPOINT="./test/structure_test"
ST_IMAGE="gcr.io/gcp-runtimes/structure_test"
CONFIG_COUNTER=0
USAGE_STRING="Usage: $0 [-i <image>] [-c <config>] [-v] [-e <entrypoint>] [--no-pull]"

CONFIG_DIR=$(pwd)/.cfg
mkdir -p "$CONFIG_DIR"
Expand All @@ -17,11 +19,22 @@ cleanup() {
}

usage() {
echo "Usage: $0 [-i <image>] [-c <config>] [-v] [-e <entrypoint>]"
echo "$USAGE_STRING"
cleanup
exit 1
}

helper() {
echo "$USAGE_STRING"
echo
echo " -i, --image image to run tests on"
echo " -c, --config path to json/yaml config file"
echo " -v display verbose testing output"
echo " -e, --entrypoint specify custom docker entrypoint for image"
echo " --no-pull don't pull latest structure test image"
exit 0
}

while test $# -gt 0; do
case "$1" in
--image|-i)
Expand All @@ -37,6 +50,13 @@ while test $# -gt 0; do
VERBOSE=1
shift
;;
--no-pull)
PULL=0
shift
;;
--help|-h)
helper
;;
--config|-c)
shift
if test $# -eq 0; then
Expand Down Expand Up @@ -72,6 +92,10 @@ if [ $VERBOSE -eq 1 ]; then
CMD_STRING=$CMD_STRING" -test.v"
fi

if [ $PULL -eq 1 ]; then
docker pull "$ST_IMAGE"
fi

docker run -d --entrypoint="/bin/sh" --name st_container "$ST_IMAGE" > /dev/null 2>&1

# shellcheck disable=SC2086
Expand Down
12 changes: 7 additions & 5 deletions structure_tests/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
)

func TestAll(t *testing.T) {
var err error
var tests StructureTest
for _, file := range configFiles {
if tests, err = Parse(file); err != nil {
tests, err := Parse(file)
if err != nil {
log.Fatalf("Error parsing config file: %s", err)
}
log.Printf("Running tests for file %s", file)
Expand Down Expand Up @@ -67,8 +66,11 @@ func Parse(fp string) (StructureTest, error) {
if st == nil {
return nil, errors.New("Unsupported schema version: " + version)
}
unmarshal(testContents, st)
tests, ok := st.(StructureTest) //type assertion

testHolder := st.New()

unmarshal(testContents, testHolder)
tests, ok := testHolder.(StructureTest) //type assertion
if !ok {
return nil, errors.New("Error encountered when type casting Structure Test interface!")
}
Expand Down
14 changes: 12 additions & 2 deletions structure_tests/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ func (a *arrayFlags) Set(value string) error {
return nil
}

var schemaVersions map[string]interface{} = map[string]interface{}{
"1.0.0": new(StructureTestv1),
var schemaVersions map[string]VersionHolder = map[string]VersionHolder{
"1.0.0": new(VersionHolderv1),
}

type SchemaVersion struct {
SchemaVersion string
}

type Unmarshaller func([]byte, interface{}) error

type VersionHolder interface {
New() StructureTest
}

type VersionHolderv1 struct{}

func (v VersionHolderv1) New() StructureTest {
return new(StructureTestv1)
}

0 comments on commit 07b3e9a

Please sign in to comment.