-
Notifications
You must be signed in to change notification settings - Fork 16
/
backend_test.go
71 lines (59 loc) · 1.99 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package azureauth
import (
"context"
"testing"
"time"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/helper/pluginutil"
"github.com/hashicorp/vault/sdk/logical"
)
type testSystemViewEnt struct {
logical.StaticSystemView
}
func (d testSystemViewEnt) GenerateIdentityToken(_ context.Context, _ *pluginutil.IdentityTokenRequest) (*pluginutil.IdentityTokenResponse, error) {
return &pluginutil.IdentityTokenResponse{}, nil
}
func getTestBackend(t *testing.T) (*azureAuthBackend, logical.Storage) {
return getTestBackendWithComputeClient(t, nil, nil, nil, nil, nil)
}
func getTestBackendWithResourceClient(t *testing.T, r resourceClientFunc, p providersClientFunc) (*azureAuthBackend, logical.Storage) {
t.Helper()
sysView := testSystemViewEnt{}
sysView.DefaultLeaseTTLVal = time.Hour * 12
sysView.MaxLeaseTTLVal = time.Hour * 24
config := &logical.BackendConfig{
Logger: log.New(&log.LoggerOptions{Level: log.Trace}),
System: &sysView,
StorageView: &logical.InmemStorage{},
}
b := backend()
err := b.Setup(context.Background(), config)
if err != nil {
t.Fatalf("unable to create backend: %v", err)
}
b.provider = &mockProvider{
resourceClientFunc: r,
providersClientFunc: p,
}
return b, config.StorageView
}
func getTestBackendWithComputeClient(t *testing.T, c computeClientFunc, v vmssClientFunc, m msiClientFunc, ml msiListFunc, g msGraphClientFunc) (*azureAuthBackend, logical.Storage) {
t.Helper()
sysView := testSystemViewEnt{}
sysView.DefaultLeaseTTLVal = time.Hour * 12
sysView.MaxLeaseTTLVal = time.Hour * 24
config := &logical.BackendConfig{
Logger: log.New(&log.LoggerOptions{Level: log.Trace}),
System: &sysView,
StorageView: &logical.InmemStorage{},
}
b := backend()
err := b.Setup(context.Background(), config)
if err != nil {
t.Fatalf("unable to create backend: %v", err)
}
b.provider = newMockProvider(c, v, m, ml, g)
return b, config.StorageView
}