-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmockclient.go
44 lines (34 loc) · 1.28 KB
/
mockclient.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package mock
import (
"context"
"fmt"
"net/http"
compute "google.golang.org/api/compute/v1"
option "google.golang.org/api/option"
corev1 "k8s.io/api/core/v1"
api "github.com/gardener/machine-controller-manager-provider-gcp/pkg/api/v1alpha1"
)
// PluginSPIImpl is the mock implementation of PluginSPIImpl
type PluginSPIImpl struct {
Client *http.Client
}
// NewComputeService creates a compute service instance using the mock
func (ms *PluginSPIImpl) NewComputeService(secrets *corev1.Secret) (context.Context, *compute.Service, error) {
ctx := context.Background()
_, serviceAccountJSON := secrets.Data[api.GCPServiceAccountJSON]
_, serviceAccountJSONAlternative := secrets.Data[api.GCPAlternativeServiceAccountJSON]
if !serviceAccountJSON && !serviceAccountJSONAlternative {
return nil, nil, fmt.Errorf("Missing secrets to connect to compute service")
}
// create a compute service using a mockclient work
client := option.WithHTTPClient(ms.Client)
endpoint := option.WithEndpoint("http://127.0.0.1:6666")
computeService, err := compute.NewService(ctx, client, endpoint)
if err != nil {
return nil, nil, err
}
return ctx, computeService, nil
}