-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdriver_testwrapper.go
49 lines (39 loc) · 1.53 KB
/
driver_testwrapper.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
package main
import (
"context"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
// these types wrap hcloud.Client to make mocking easier
type hetznerClienter interface {
Volume() hetznerVolumeClienter
Server() hetznerServerClienter
Action() hetznerActionClienter
}
type hetznerVolumeClienter interface {
All(context.Context) ([]*hcloud.Volume, error)
Attach(context.Context, *hcloud.Volume, *hcloud.Server) (*hcloud.Action, *hcloud.Response, error)
ChangeProtection(context.Context, *hcloud.Volume, hcloud.VolumeChangeProtectionOpts) (*hcloud.Action, *hcloud.Response, error)
Create(context.Context, hcloud.VolumeCreateOpts) (hcloud.VolumeCreateResult, *hcloud.Response, error)
Delete(context.Context, *hcloud.Volume) (*hcloud.Response, error)
Detach(context.Context, *hcloud.Volume) (*hcloud.Action, *hcloud.Response, error)
GetByName(context.Context, string) (*hcloud.Volume, *hcloud.Response, error)
}
type hetznerServerClienter interface {
GetByID(ctx context.Context, id int64) (*hcloud.Server, *hcloud.Response, error)
GetByName(ctx context.Context, name string) (*hcloud.Server, *hcloud.Response, error)
}
type hetznerActionClienter interface {
WatchProgress(ctx context.Context, action *hcloud.Action) (<-chan int, <-chan error)
}
type hetznerClient struct {
client *hcloud.Client
}
func (h *hetznerClient) Volume() hetznerVolumeClienter {
return &h.client.Volume
}
func (h *hetznerClient) Server() hetznerServerClienter {
return &h.client.Server
}
func (h *hetznerClient) Action() hetznerActionClienter {
return &h.client.Action
}