@@ -26,8 +26,10 @@ import (
26
26
"github.com/elastic/cloud-sdk-go/pkg/api"
27
27
"github.com/elastic/cloud-sdk-go/pkg/api/mock"
28
28
"github.com/elastic/cloud-sdk-go/pkg/models"
29
+ "github.com/elastic/cloud-sdk-go/pkg/util/ec"
29
30
"github.com/hashicorp/go-multierror"
30
31
32
+ "github.com/elastic/ecctl/pkg/deployment"
31
33
"github.com/elastic/ecctl/pkg/util"
32
34
)
33
35
@@ -39,7 +41,7 @@ func TestUpgradeStateless(t *testing.T) {
39
41
}
40
42
internalErrorBytes , _ := json .MarshalIndent (internalError , "" , " " )
41
43
type args struct {
42
- params UpgradeStatelessParams
44
+ params deployment. ResourceParams
43
45
}
44
46
tests := []struct {
45
47
name string
@@ -54,31 +56,55 @@ func TestUpgradeStateless(t *testing.T) {
54
56
util .ErrAPIReq ,
55
57
errors .New ("id \" \" is invalid" ),
56
58
errors .New ("deployment resource type cannot be empty" ),
59
+ errors .New ("failed auto-discovering the resource ref id: api reference is required for command" ),
60
+ errors .New (`failed auto-discovering the resource ref id: id "" is invalid` ),
57
61
}},
58
62
},
59
63
{
60
64
name : "fails due to API error" ,
61
- args : args {params : UpgradeStatelessParams {
65
+ args : args {params : deployment. ResourceParams {
62
66
API : api .NewMock (mock .New404Response (mock .NewStructBody (internalError ))),
63
67
DeploymentID : util .ValidClusterID ,
68
+ RefID : "main-kibana" ,
64
69
Type : "kibana" ,
65
70
}},
66
71
err : errors .New (string (internalErrorBytes )),
67
72
},
68
73
{
69
74
name : "succeeds" ,
70
- args : args {params : UpgradeStatelessParams {
75
+ args : args {params : deployment. ResourceParams {
71
76
API : api .NewMock (mock .New202Response (mock .NewStringBody ("" ))),
72
77
DeploymentID : util .ValidClusterID ,
73
78
Type : "kibana" ,
79
+ RefID : "main-kibana" ,
74
80
}},
75
81
want : new (models.DeploymentResourceUpgradeResponse ),
76
82
},
83
+ {
84
+ name : "succeeds when RefID is not set" ,
85
+ args : args {params : deployment.ResourceParams {
86
+ API : api .NewMock (
87
+ mock .New200Response (mock .NewStructBody (models.DeploymentGetResponse {
88
+ Healthy : ec .Bool (true ),
89
+ ID : ec .String ("3531aaf988594efa87c1aabb7caed337" ),
90
+ Resources : & models.DeploymentResources {
91
+ Elasticsearch : []* models.ElasticsearchResourceInfo {{
92
+ ID : ec .String ("3531aaf988594efa87c1aabb7caed337" ),
93
+ RefID : ec .String ("elasticsearch" ),
94
+ }},
95
+ },
96
+ })),
97
+ mock .New200Response (mock .NewStringBody ("" )),
98
+ ),
99
+ DeploymentID : util .ValidClusterID ,
100
+ Type : "elasticsearch" ,
101
+ }},
102
+ },
77
103
}
78
104
for _ , tt := range tests {
79
105
t .Run (tt .name , func (t * testing.T ) {
80
106
got , err := UpgradeStateless (tt .args .params )
81
- if ! reflect . DeepEqual ( err , tt .err ) {
107
+ if tt . err != nil && err . Error () != tt .err . Error ( ) {
82
108
t .Errorf ("UpgradeStateless() error = %v, wantErr %v" , err , tt .err )
83
109
return
84
110
}
0 commit comments