55package cmd_test
66
77import (
8+ "encoding/json"
89 "net/http"
910
1011 "github.com/jarcoal/httpmock"
@@ -29,7 +30,69 @@ func (ms *MockSuite) TestCloudRancherCreateCmd(assert, require *td.T) {
2930 )
3031
3132 out , err := cmd .Execute ("cloud" , "rancher" , "create" , "--cloud-project" , "fakeProjectID" , "--name" , "test-rancher" , "--plan" , "OVHCLOUD_EDITION" , "--version" , "2.11.3" )
32-
3333 require .CmpNoError (err )
3434 assert .String (out , `✅ Rancher test-rancher created successfully (id: rancher-12345)` )
3535}
36+
37+ func (ms * MockSuite ) TestCloudRancherCreateCmdJSONFormat (assert , require * td.T ) {
38+ httpmock .RegisterMatcherResponder (http .MethodPost ,
39+ "https://eu.api.ovh.com/v2/publicCloud/project/fakeProjectID/rancher" ,
40+ tdhttpmock .JSONBody (td .JSON (`
41+ {
42+ "targetSpec": {
43+ "name": "test-rancher",
44+ "plan": "OVHCLOUD_EDITION",
45+ "version": "2.11.3"
46+ }
47+ }` ),
48+ ),
49+ httpmock .NewStringResponder (200 , `{"id": "rancher-12345"}` ),
50+ )
51+
52+ out , err := cmd .Execute ("cloud" , "rancher" , "create" , "--cloud-project" , "fakeProjectID" , "--name" , "test-rancher" , "--plan" , "OVHCLOUD_EDITION" , "--version" , "2.11.3" , "--json" )
53+ require .CmpNoError (err )
54+ assert .Cmp (json .RawMessage (out ), td .JSON (`{"details":{"id": "rancher-12345"}, "message": "✅ Rancher test-rancher created successfully (id: rancher-12345)"}` ))
55+ }
56+
57+ func (ms * MockSuite ) TestCloudRancherCreateCmdYAMLFormat (assert , require * td.T ) {
58+ httpmock .RegisterMatcherResponder (http .MethodPost ,
59+ "https://eu.api.ovh.com/v2/publicCloud/project/fakeProjectID/rancher" ,
60+ tdhttpmock .JSONBody (td .JSON (`
61+ {
62+ "targetSpec": {
63+ "name": "test-rancher",
64+ "plan": "OVHCLOUD_EDITION",
65+ "version": "2.11.3"
66+ }
67+ }` ),
68+ ),
69+ httpmock .NewStringResponder (200 , `{"id": "rancher-12345"}` ),
70+ )
71+
72+ out , err := cmd .Execute ("cloud" , "rancher" , "create" , "--cloud-project" , "fakeProjectID" , "--name" , "test-rancher" , "--plan" , "OVHCLOUD_EDITION" , "--version" , "2.11.3" , "--yaml" )
73+ require .CmpNoError (err )
74+ assert .String (out , `details:
75+ id: rancher-12345
76+ message: '✅ Rancher test-rancher created successfully (id: rancher-12345)'
77+ ` )
78+ }
79+
80+ func (ms * MockSuite ) TestCloudRancherCreateCmdCustomFormat (assert , require * td.T ) {
81+ httpmock .RegisterMatcherResponder (http .MethodPost ,
82+ "https://eu.api.ovh.com/v2/publicCloud/project/fakeProjectID/rancher" ,
83+ tdhttpmock .JSONBody (td .JSON (`
84+ {
85+ "targetSpec": {
86+ "name": "test-rancher",
87+ "plan": "OVHCLOUD_EDITION",
88+ "version": "2.11.3"
89+ }
90+ }` ),
91+ ),
92+ httpmock .NewStringResponder (200 , `{"id": "rancher-12345"}` ),
93+ )
94+
95+ out , err := cmd .Execute ("cloud" , "rancher" , "create" , "--cloud-project" , "fakeProjectID" , "--name" , "test-rancher" , "--plan" , "OVHCLOUD_EDITION" , "--version" , "2.11.3" , "--format" , "[details.id]" )
96+ require .CmpNoError (err )
97+ assert .String (out , `["rancher-12345"]` )
98+ }
0 commit comments