forked from kyma-project/control-plane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_client.go
94 lines (76 loc) · 2.12 KB
/
fake_client.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
package provisioner
import (
"fmt"
"sync"
"github.com/google/uuid"
schema "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema"
)
type runtime struct {
runtimeInput schema.ProvisionRuntimeInput
}
type fakeClient struct {
mu sync.Mutex
runtimes []runtime
operations map[string]schema.OperationStatus
}
func NewFakeClient() *fakeClient {
return &fakeClient{
runtimes: []runtime{},
operations: make(map[string]schema.OperationStatus, 1),
}
}
func (c *fakeClient) GetProvisionRuntimeInput(index int) schema.ProvisionRuntimeInput {
c.mu.Lock()
defer c.mu.Unlock()
r := c.runtimes[index]
return r.runtimeInput
}
func (c *fakeClient) FinishProvisionerOperation(id string, state schema.OperationState) {
c.mu.Lock()
defer c.mu.Unlock()
op := c.operations[id]
op.State = state
c.operations[id] = op
}
func (c *fakeClient) SetOperation(id string, operation schema.OperationStatus) {
c.mu.Lock()
defer c.mu.Unlock()
c.operations[id] = operation
}
// Provisioner Client methods
func (c *fakeClient) ProvisionRuntime(accountID, subAccountID string, config schema.ProvisionRuntimeInput) (schema.OperationStatus, error) {
c.mu.Lock()
defer c.mu.Unlock()
rid := uuid.New().String()
opId := uuid.New().String()
c.runtimes = append(c.runtimes, runtime{
runtimeInput: config,
})
c.operations = map[string]schema.OperationStatus{
opId: {
ID: &opId,
RuntimeID: &rid,
Operation: schema.OperationTypeProvision,
State: schema.OperationStateInProgress,
},
}
return schema.OperationStatus{
RuntimeID: &rid,
ID: &opId,
}, nil
}
func (c *fakeClient) DeprovisionRuntime(accountID, runtimeID string) (string, error) {
return uuid.New().String(), nil
}
func (c *fakeClient) ReconnectRuntimeAgent(accountID, runtimeID string) (string, error) {
return "", fmt.Errorf("not implemented")
}
func (c *fakeClient) RuntimeOperationStatus(accountID, operationID string) (schema.OperationStatus, error) {
c.mu.Lock()
defer c.mu.Unlock()
o, found := c.operations[operationID]
if !found {
return schema.OperationStatus{}, fmt.Errorf("operation not found")
}
return o, nil
}