forked from edwardsp/lemur
/
testing.go
129 lines (108 loc) · 2.9 KB
/
testing.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2018 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package dmplugin
import (
lustre "github.com/wastore/go-lustre"
"github.com/intel-hpdd/logging/alert"
)
// Fataler provides Fatal and Fatalf
type Fataler interface {
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
}
// TestAction is an Action implementation used for testing Movers.
type TestAction struct {
t Fataler
id uint64
path string
offset int64
length int64
data []byte
uuid string
hash []byte
url string
ActualLength int
Updates int
}
// NewTestAction returns a stub action that can be used for testing.
func NewTestAction(t Fataler, path string, offset int64, length int64, uuid string, data []byte) *TestAction {
return &TestAction{
t: t,
id: 1,
path: path,
offset: offset,
length: length,
uuid: uuid,
data: data,
}
}
// Update sends an action status update
func (a *TestAction) Update(offset, length, max int64) error {
a.Updates++
return nil
}
// Complete signals that the action has completed
func (a *TestAction) Complete() error {
return nil
}
// Fail signals that the action has failed
func (a *TestAction) Fail(err error) error {
alert.Warnf("fail: id:%d %v", a.id, err)
return nil
}
// ID returns the action item's ID
func (a *TestAction) ID() uint64 {
return a.id
}
// Offset returns the current offset of the action item
func (a *TestAction) Offset() int64 {
return a.offset
}
// Length returns the expected length of the action item's file
func (a *TestAction) Length() int64 {
return a.length
}
// Data returns a byte slice of the action item's data
func (a *TestAction) Data() []byte {
return a.data
}
// PrimaryPath returns the action item's primary file path
func (a *TestAction) PrimaryPath() string {
return a.path
}
// WritePath returns the action item's write path (e.g. for restores)
func (a *TestAction) WritePath() string {
return a.path
}
// UUID returns the action item's file id
func (a *TestAction) UUID() string {
return a.uuid
}
// Hash returns the action item's file id
func (a *TestAction) Hash() []byte {
return a.hash
}
// URL returns the action item's file id
func (a *TestAction) URL() string {
return a.url
}
// SetUUID returns the action item's file id
func (a *TestAction) SetUUID(u string) {
a.uuid = u
}
// SetHash sets the action's file id
func (a *TestAction) SetHash(id []byte) {
a.hash = id
}
// SetURL returns the action item's file id
func (a *TestAction) SetURL(u string) {
a.url = u
}
// SetActualLength sets the action's actual file length
func (a *TestAction) SetActualLength(length int64) {
if a.length != lustre.MaxExtentLength && length != a.length {
a.t.Fatalf("actual length does not match original %d != %d", length, a.length)
}
a.ActualLength = int(length)
}