Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhollingworth committed Oct 11, 2022
1 parent 6809e47 commit cfb12c5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/merge/merge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main_test

import (
"os"
"testing"

merge "github.com/libremfg/go-tools/cmd/merge"
)

func TestMerge(t *testing.T) {
d := "./test/"
e := []string{".txt"}
o := "./output"
v := false

t.Cleanup(func() {
_, err := os.Stat(o)
if err == nil {
os.Remove(o)
}
})

merge.Merge(d, e, o, v)

expect := []byte("1\r\n2\r\n3\r\n")

actual, err := os.ReadFile(o)
if err != nil {
t.Error(err)
}

if len(expect) != len(actual) {
t.Errorf("lengths don't match expect %d got %d", len(expect), len(actual))
return
}

for i := 0; i < len(expect); i++ {
if expect[i] != actual[i] {
t.Errorf("index %d don't match expect %b got %b", i, expect[i], actual[i])
}
}
}
1 change: 1 addition & 0 deletions cmd/merge/test/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions cmd/merge/test/file2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
1 change: 1 addition & 0 deletions cmd/merge/test/file3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3

0 comments on commit cfb12c5

Please sign in to comment.