-
Notifications
You must be signed in to change notification settings - Fork 787
/
fake.go
64 lines (53 loc) · 1.59 KB
/
fake.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
package fake
import (
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cluster"
"github.com/jenkins-x/jx/v2/pkg/util"
)
// Client a fake implementation of the cluster client
type Client struct {
Clusters []*cluster.Cluster
}
// verify we implement the interface
var _ cluster.Client = &Client{}
// NewClient create a new fake client for testing
func NewClient(clusters []*cluster.Cluster) *Client {
return &Client{
Clusters: clusters,
}
}
// List lists the clusters
func (c *Client) List() ([]*cluster.Cluster, error) {
return c.Clusters, nil
}
// ListFilter lists the clusters with a filter
func (c *Client) ListFilter(labels map[string]string) ([]*cluster.Cluster, error) {
return cluster.ListFilter(c, labels)
}
// Connect connects to a cluster
func (c *Client) Connect(cluster *cluster.Cluster) error {
log.Logger().Infof("fake cluster connecting to cluster: %s", util.ColorInfo(cluster.Name))
return nil
}
// String return the string representation
func (c *Client) String() string {
return "Client"
}
// Get looks up a cluster by name
func (c *Client) Get(name string) (*cluster.Cluster, error) {
return cluster.GetCluster(c, name)
}
// Delete should delete the cluster from the clusters list
func (c *Client) Delete(cluster *cluster.Cluster) error {
for i, v := range c.Clusters {
if v.Name == cluster.Name {
c.Clusters = append(c.Clusters[:i], c.Clusters[i+1:]...)
}
}
return nil
}
// SetClusterLabels labels the given cluster
func (c *Client) SetClusterLabels(cluster *cluster.Cluster, labels map[string]string) error {
cluster.Labels = labels
return nil
}