-
Notifications
You must be signed in to change notification settings - Fork 55
/
barkup_test.go
83 lines (67 loc) · 1.85 KB
/
barkup_test.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package barkup
import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"os"
"reflect"
"testing"
)
func expect(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
}
}
func refute(t *testing.T, a interface{}, b interface{}) {
if a == b {
t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
}
}
func testServer(code int, body string, contentType string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(code)
w.Header().Set("Content-Type", contentType)
fmt.Fprintln(w, body)
}))
}
//////
func Test_ExportRestult_To_Move(t *testing.T) {
file, _ := os.Create("to_mv_test")
defer file.Close()
e := ExportResult{"to_mv_test", "text/plain", nil}
storeErr := e.To("test/", nil)
expect(t, storeErr, (*Error)(nil))
err := os.Remove("test/to_mv_test")
expect(t, err, nil)
}
type StoreSuccessStory struct{}
func (x *StoreSuccessStory) Store(r *ExportResult, d string) *Error {
return nil
}
type StoreFailureStory struct{}
func (x *StoreFailureStory) Store(r *ExportResult, d string) *Error {
return &Error{
err: errors.New("*****"),
}
}
func Test_ExportRestult_To_Store(t *testing.T) {
_, _ = os.Create("test/test.txt")
e := &ExportResult{"test/test.txt", "text/plain", nil}
err := e.To("test/", &StoreSuccessStory{})
expect(t, err, (*Error)(nil))
}
func Test_ExportRestult_To_Store_Fail(t *testing.T) {
_, _ = os.Create("test/test.txt")
e := &ExportResult{"test/test.txt", "text/plain", nil}
err := e.To("test/", &StoreFailureStory{})
refute(t, err, (*Error)(nil))
}
/// Error
func Test_Error(t *testing.T) {
e := Error{
err: fmt.Errorf("cheese"),
CmdOutput: "CHEEEEES",
}
expect(t, e.Error(), "cheese")
}