-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryptedfilemanagment_test.go
More file actions
57 lines (46 loc) · 1.21 KB
/
encryptedfilemanagment_test.go
File metadata and controls
57 lines (46 loc) · 1.21 KB
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
52
53
54
55
56
57
package main
import (
"fmt"
"testing"
)
type loginTest struct {
User string `json:"user"`
Password string `json:"password"`
}
func TestEncryptedfilemanagment(t *testing.T) {
path := getHomePath("things-gui_test")
logCh := make(chan string, 1)
go func() {
for p := range logCh {
fmt.Printf("%s", p)
}
}()
mappingIn := map[string]loginTest{
"John": loginTest{User: "John", Password: "pass1"},
"Jane": loginTest{User: "Jane", Password: "pass2"},
"Mary": loginTest{User: "Mary", Password: "pass3"},
}
mappingOut := make(map[string]loginTest)
_, err := createFile(path, logCh)
if err != nil {
t.Errorf("Creating file FAILED: %s\n", err)
}
err = writeEncryptedFile(path, mappingIn, logCh)
if err != nil {
t.Errorf("Writing file FAILED: %s\n", err)
}
err = readEncryptedFile(path, &mappingOut, logCh)
if err != nil {
t.Errorf("Reading encrypted file FAILED: %s\n", err)
}
if mappingIn["John"].Password != mappingOut["John"].Password {
t.Errorf("TEST 4: FAILED. Encrypting file management.\n")
}
err = deleteFile(path, logCh)
if err != nil {
t.Errorf("Deleting encrypted file FAILED: %s\n", err)
}
if !fileNotExist(path) {
t.Errorf("TEST 5: Deleting encrypted file FAILED\n")
}
}