Skip to content

Commit

Permalink
chore: test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Sep 14, 2023
1 parent b1f1971 commit 224161a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions internal/util/io_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package util

import (
"fmt"
"math/rand"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCopyFile(t *testing.T) {
path := GetCIPath("../..")
seed := rand.Int()
fn := fmt.Sprintf("/tmp/README.md.%d", seed)
CopyFile(path+"/../README.md", fn)
if assert.FileExists(t, fn) {
os.Remove(fn)
}
}
3 changes: 1 addition & 2 deletions internal/util/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/md5"
"encoding/hex"
"io"
"log"
"os"
)

Expand All @@ -13,7 +12,7 @@ func MD5CheckSum(path string) (string, error) {
h := md5.New()
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
return "", err
}
defer f.Close()
if _, err := io.Copy(h, f); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/util/md5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ func TestMD5(t *testing.T) {
md5, err := MD5CheckSum(path)
assert.NoError(t, err)
assert.Equal(t, "3ba7c806a52baf4efbfb4962f62a36d1", md5)

_, err = MD5CheckSum("/tmp/some/123/3ba7c806a52baf4efbfb4962f62a36d1")
assert.Error(t, err)
}

0 comments on commit 224161a

Please sign in to comment.