-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend_test.go
56 lines (46 loc) · 1.47 KB
/
backend_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
package artifactory
import (
"context"
"testing"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/logical"
)
func newBackend(t *testing.T) (logical.Backend, logical.Storage) {
defaultLeaseTTLVal := time.Hour * 12
maxLeaseTTLVal := time.Hour * 24
config := &logical.BackendConfig{
Logger: logging.NewVaultLogger(log.Trace),
System: &logical.StaticSystemView{
DefaultLeaseTTLVal: defaultLeaseTTLVal,
MaxLeaseTTLVal: maxLeaseTTLVal,
},
StorageView: &logical.InmemStorage{},
}
b, err := Factory(context.Background(), config)
if err != nil {
t.Fatalf("unable to create backend: %v", err)
}
return b, config.StorageView
}
// Assertion helpers to handle the ternary logic of making a logical.Request
type Expectation int
const (
ExpectedToSucceed Expectation = iota
FailWithError
FailWithLogicalError
)
func assertLogicalResponse(t *testing.T, expectation Expectation, err error, resp *logical.Response) {
if err != nil || (resp != nil && resp.IsError()) {
if expectation == ExpectedToSucceed {
t.Fatalf("Expected test case to succeed, got err:%s resp:%#v\n", err, resp)
}
}
if expectation == FailWithError && err == nil {
t.Fatalf("Expected test case to fail with error but succeeded: resp:%#v\n", resp)
}
if expectation == FailWithLogicalError && resp != nil && !resp.IsError() {
t.Fatalf("Expected test case to fail with logical error but succeeded: resp:%#v\n", resp)
}
}