Skip to content

Commit

Permalink
Improve test organization (just helper stuff in misc_test.go)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Jun 21, 2018
1 parent 87e36d1 commit e71a8e5
Show file tree
Hide file tree
Showing 4 changed files with 623 additions and 620 deletions.
75 changes: 75 additions & 0 deletions misc_test.go
@@ -0,0 +1,75 @@
package scipipe

import (
"os"
"path/filepath"
"reflect"
"sync"
"testing"
)

var initTestLogsLock sync.Mutex

// --------------------------------------------------------------------------------
// Testing Helper stuff
// --------------------------------------------------------------------------------

func initTestLogs() {
if Warning == nil {
//InitLogDebug()
InitLogWarning()
}
}

func cleanFiles(fileNames ...string) {
Debug.Println("Starting to remove files:", fileNames)
for _, fileName := range fileNames {
auditFileName := fileName + ".audit.json"
if _, err := os.Stat(fileName); err == nil {
os.Remove(fileName)
Debug.Println("Successfully removed file", fileName)
}
if _, err := os.Stat(auditFileName); err == nil {
os.Remove(auditFileName)
Debug.Println("Successfully removed audit.json file", auditFileName)
}
}
}

func cleanFilePatterns(filePatterns ...string) {
for _, pattern := range filePatterns {
if matches, err := filepath.Glob(pattern); err == nil {
for _, file := range matches {
if err := os.Remove(file); err != nil {
Failf("Could not remove file: %s\nError: %v\n", file, err)
}
}
} else {
Failf("Could not glob pattern: %s\nError: %v\n", pattern, err)
}
}
}

func assertIsType(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(reflect.TypeOf(expected), reflect.TypeOf(actual)) {
t.Errorf("Types do not match! (%s) and (%s)\n", reflect.TypeOf(expected).String(), reflect.TypeOf(actual).String())
}
}

func assertNil(t *testing.T, obj interface{}, msgs ...interface{}) {
if obj != nil {
t.Errorf("Object is not nil: %v. Message: %v\n", obj, msgs)
}
}

func assertNotNil(t *testing.T, obj interface{}, msgs ...interface{}) {
if obj == nil {
t.Errorf("Object is nil, which it should not be: %v. Message: %v\n", obj, msgs)
}
}

func assertEqualValues(t *testing.T, expected interface{}, actual interface{}, msgs ...interface{}) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Values are not equal (Expected: %v, Actual: %v)\n", expected, actual)
}
}
18 changes: 18 additions & 0 deletions port_test.go
Expand Up @@ -161,3 +161,21 @@ func TestOutParamPortFrom(t *testing.T) {
t.Errorf("OutParamPort not among remote ports in InParamPort")
}
}

func TestConnectBackwards(t *testing.T) {
initTestLogs()

wf := NewWorkflow("TestConnectBackwards", 16)

p1 := wf.NewProc("p1", "echo foo > {o:foo}")
p1.SetPathCustom("foo", func(t *Task) string { return "foo.txt" })

p2 := wf.NewProc("p2", "sed 's/foo/bar/g' {i:foo} > {o:bar}")
p2.SetPathCustom("bar", func(t *Task) string { return t.InPath("foo") + ".bar.txt" })

p1.Out("foo").To(p2.In("foo"))

wf.Run()

cleanFiles("foo.txt", "foo.txt.bar.txt")
}

0 comments on commit e71a8e5

Please sign in to comment.