@@ -19,88 +19,17 @@ package cmdutil
19
19
20
20
import (
21
21
"errors"
22
- "net/http"
23
22
"reflect"
24
23
"strconv"
25
24
"testing"
26
25
"time"
27
26
28
- "github.com/elastic/cloud-sdk-go/pkg/api"
29
- "github.com/elastic/cloud-sdk-go/pkg/api/mock"
30
- "github.com/elastic/cloud-sdk-go/pkg/models"
31
- "github.com/elastic/cloud-sdk-go/pkg/util/ec"
32
27
"github.com/spf13/cobra"
33
28
flag "github.com/spf13/pflag"
34
29
35
30
"github.com/elastic/ecctl/pkg/util"
36
31
)
37
32
38
- func TestGetInstances (t * testing.T ) {
39
- cmdWithSliceFlag := & cobra.Command {
40
- Use : "something" ,
41
- Run : func (cmd * cobra.Command , args []string ) {},
42
- }
43
- cmdWithSliceFlag .Flags ().StringSlice ("instance" , []string {"1" , "2" , "3" }, "instance" )
44
- cmdWithSliceFlag .Flags ().Bool ("all" , false , "all" )
45
- cmdWithAllFlag := & cobra.Command {
46
- Use : "something" ,
47
- Run : func (cmd * cobra.Command , args []string ) {},
48
- }
49
- cmdWithAllFlag .Flags ().Bool ("all" , true , "all" )
50
- type args struct {
51
- cmd * cobra.Command
52
- params util.ClusterParams
53
- flagName string
54
- }
55
- tests := []struct {
56
- name string
57
- args args
58
- want []string
59
- err error
60
- }{
61
- {
62
- name : "obtains the instances explicitly set" ,
63
- args : args {
64
- cmd : cmdWithSliceFlag ,
65
- flagName : "instance" ,
66
- },
67
- want : []string {"1" , "2" , "3" },
68
- },
69
- {
70
- name : "obtains the instances from the cluster topology" ,
71
- args : args {
72
- cmd : cmdWithAllFlag ,
73
- params : util.ClusterParams {
74
- ClusterID : util .ValidClusterID ,
75
- API : api .NewMock (mock.Response {Response : http.Response {
76
- StatusCode : 200 ,
77
- Body : mock .NewStructBody (models.ElasticsearchClusterInfo {
78
- Topology : & models.ClusterTopologyInfo {
79
- Instances : []* models.ClusterInstanceInfo {
80
- {InstanceName : ec .String ("instance-000000" )},
81
- },
82
- },
83
- }),
84
- }}),
85
- },
86
- },
87
- want : []string {"instance-000000" },
88
- },
89
- }
90
- for _ , tt := range tests {
91
- t .Run (tt .name , func (t * testing.T ) {
92
- got , err := GetInstances (tt .args .cmd , tt .args .params , tt .args .flagName )
93
- if ! reflect .DeepEqual (err , tt .err ) {
94
- t .Errorf ("GetInstances() error = %v, wantErr %v" , err , tt .err )
95
- return
96
- }
97
- if ! reflect .DeepEqual (got , tt .want ) {
98
- t .Errorf ("GetInstances() = %v, want %v" , got , tt .want )
99
- }
100
- })
101
- }
102
- }
103
-
104
33
func TestAddKindFlag (t * testing.T ) {
105
34
var wantSomethingAssert = & flag.Flag {
106
35
Name : "kind" ,
0 commit comments