aboutsummaryrefslogtreecommitdiff
path: root/fileop/fileop_test.go
blob: 134090d849bf84a0aebff49f71f5530caa836224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package fileop

import (
	"fmt"
	"os"
	"porg/testutil"
	"testing"
)

func TestMove(t *testing.T) {
	src := testutil.CreateTmpFile()
	dest := fmt.Sprintf("/tmp/%s", testutil.RandomString(10))

	c := Move()

	c <- &MoveCommand{Source: src, Destination: dest}
	close(c)

	if _, err := os.Stat(dest); err != nil {
		t.Errorf("File %s not moved to %s", src, dest)
	}

}

func TestIsEmpty(t *testing.T) {
	folder := testutil.CreateFolder()

	empty, err := IsEmpty(folder)

	if err != nil {
		t.Fatalf("Error reading the folder %s", err.Error())
	}

	if !empty {
		t.Errorf("Folder is not empty %s", folder)
	}

}

func TestCalculateSHA256(t *testing.T) {

	if f, err := os.Open("test_file.txt"); err != nil {
		t.Error(err)
	} else {
		sh256, _ := CalculateSHA256(f)
		if sh256 != "027cc886f9b8c866f932ef8b8da9a32f0857ef8e16ec98dd2797021b34623b88" {
			t.Errorf("Wrong sh256 hash, given %s", sh256)
		}
	}

}