Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve test organization (just helper stuff in misc_test.go)
- Loading branch information
Showing
4 changed files
with
623 additions
and
620 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
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
Oops, something went wrong.