summaryrefslogtreecommitdiff
path: root/integrationtests/fileutils.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-24 14:06:11 +0300
committerPaul Buetow <paul@buetow.org>2021-10-24 14:06:11 +0300
commit6cfc4e161f94ab159d4b1ea491ffe6f166fa6204 (patch)
tree093fb4bff0bdf086188df86ca5d13dc7f8a34e4f /integrationtests/fileutils.go
parent87b6c47999f49c2deff42fdcc703c419b251bdbc (diff)
Integration tests can run concurrently, so we now have unique TCP ports for each
Diffstat (limited to 'integrationtests/fileutils.go')
-rw-r--r--integrationtests/fileutils.go59
1 files changed, 38 insertions, 21 deletions
diff --git a/integrationtests/fileutils.go b/integrationtests/fileutils.go
index 1a55732..d13617d 100644
--- a/integrationtests/fileutils.go
+++ b/integrationtests/fileutils.go
@@ -12,28 +12,28 @@ import (
"testing"
)
-// Checks whether both files have the same lines (order doesn't matter)
-func compareFilesContents(t *testing.T, fileA, fileB string) error {
- mapFile := func(file string) (map[string]int, error) {
- t.Log("Reading", file)
- contents := make(map[string]int)
- fd, err := os.Open(file)
- if err != nil {
- return contents, err
- }
- defer fd.Close()
-
- scanner := bufio.NewScanner(fd)
- scanner.Split(bufio.ScanLines)
- for scanner.Scan() {
- line := scanner.Text()
- count, _ := contents[line]
- contents[line] = count + 1
- }
+func mapFile(t *testing.T, file string) (map[string]int, error) {
+ t.Log("Mapping", file)
+ contents := make(map[string]int)
+ fd, err := os.Open(file)
+ if err != nil {
+ return contents, err
+ }
+ defer fd.Close()
- return contents, nil
+ scanner := bufio.NewScanner(fd)
+ scanner.Split(bufio.ScanLines)
+ for scanner.Scan() {
+ line := scanner.Text()
+ count, _ := contents[line]
+ contents[line] = count + 1
}
+ return contents, nil
+}
+
+// Checks whether both files have the same lines (order doesn't matter)
+func compareFilesContents(t *testing.T, fileA, fileB string) error {
compareMaps := func(a, b map[string]int) error {
for line, countA := range a {
countB, ok := b[line]
@@ -49,11 +49,11 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error {
}
// Read files into maps.
- a, err := mapFile(fileA)
+ a, err := mapFile(t, fileA)
if err != nil {
return err
}
- b, err := mapFile(fileB)
+ b, err := mapFile(t, fileB)
if err != nil {
return err
}
@@ -90,6 +90,23 @@ func compareFiles(t *testing.T, fileA, fileB string) error {
return nil
}
+func fileContainsStr(t *testing.T, file, str string) error {
+ t.Log("Checking if file contains string", file, str)
+ m, err := mapFile(t, file)
+ if err != nil {
+ return err
+ }
+
+ for line := range m {
+ if strings.Contains(line, str) {
+ t.Log(line)
+ return nil
+ }
+ }
+
+ return fmt.Errorf("File %s does not contain string %s", file, str)
+}
+
func shaOfFile(t *testing.T, file string) string {
bytes, err := ioutil.ReadFile(file)
if err != nil {