11package context
22
33import (
4+ "fmt"
45 "io/ioutil"
56 "os"
67 "testing"
@@ -154,6 +155,8 @@ func TestCreateOrchestratorEmpty(t *testing.T) {
154155 Docker : map [string ]string {},
155156 })
156157 assert .NilError (t , err )
158+ assert .Equal (t , "test\n " , cli .OutBuffer ().String ())
159+ assert .Equal (t , "Successfully created context \" test\" \n " , cli .ErrBuffer ().String ())
157160}
158161
159162func validateTestKubeEndpoint (t * testing.T , s store.Reader , name string ) {
@@ -189,6 +192,8 @@ func TestCreateOrchestratorAllKubernetesEndpointFromCurrent(t *testing.T) {
189192 cli , cleanup := makeFakeCli (t )
190193 defer cleanup ()
191194 createTestContextWithKube (t , cli )
195+ assert .Equal (t , "test\n " , cli .OutBuffer ().String ())
196+ assert .Equal (t , "Successfully created context \" test\" \n " , cli .ErrBuffer ().String ())
192197 validateTestKubeEndpoint (t , cli .ContextStore (), "test" )
193198}
194199
@@ -225,6 +230,7 @@ func TestCreateFromContext(t *testing.T) {
225230 defer cleanup ()
226231 revert := env .Patch (t , "KUBECONFIG" , "./testdata/test-kubeconfig" )
227232 defer revert ()
233+ cli .ResetOutputBuffers ()
228234 assert .NilError (t , RunCreate (cli , & CreateOptions {
229235 Name : "original" ,
230236 Description : "original description" ,
@@ -236,6 +242,10 @@ func TestCreateFromContext(t *testing.T) {
236242 },
237243 DefaultStackOrchestrator : "swarm" ,
238244 }))
245+ assert .Equal (t , "original\n " , cli .OutBuffer ().String ())
246+ assert .Equal (t , "Successfully created context \" original\" \n " , cli .ErrBuffer ().String ())
247+
248+ cli .ResetOutputBuffers ()
239249 assert .NilError (t , RunCreate (cli , & CreateOptions {
240250 Name : "dummy" ,
241251 Description : "dummy description" ,
@@ -247,11 +257,14 @@ func TestCreateFromContext(t *testing.T) {
247257 },
248258 DefaultStackOrchestrator : "swarm" ,
249259 }))
260+ assert .Equal (t , "dummy\n " , cli .OutBuffer ().String ())
261+ assert .Equal (t , "Successfully created context \" dummy\" \n " , cli .ErrBuffer ().String ())
250262
251263 cli .SetCurrentContext ("dummy" )
252264
253265 for _ , c := range cases {
254266 t .Run (c .name , func (t * testing.T ) {
267+ cli .ResetOutputBuffers ()
255268 err := RunCreate (cli , & CreateOptions {
256269 From : "original" ,
257270 Name : c .name ,
@@ -261,6 +274,8 @@ func TestCreateFromContext(t *testing.T) {
261274 Kubernetes : c .kubernetes ,
262275 })
263276 assert .NilError (t , err )
277+ assert .Equal (t , c .name + "\n " , cli .OutBuffer ().String ())
278+ assert .Equal (t , fmt .Sprintf ("Successfully created context %q\n " , c .name ), cli .ErrBuffer ().String ())
264279 newContext , err := cli .ContextStore ().GetMetadata (c .name )
265280 assert .NilError (t , err )
266281 newContextTyped , err := command .GetDockerContext (newContext )
@@ -308,6 +323,7 @@ func TestCreateFromCurrent(t *testing.T) {
308323 defer cleanup ()
309324 revert := env .Patch (t , "KUBECONFIG" , "./testdata/test-kubeconfig" )
310325 defer revert ()
326+ cli .ResetOutputBuffers ()
311327 assert .NilError (t , RunCreate (cli , & CreateOptions {
312328 Name : "original" ,
313329 Description : "original description" ,
@@ -319,17 +335,22 @@ func TestCreateFromCurrent(t *testing.T) {
319335 },
320336 DefaultStackOrchestrator : "swarm" ,
321337 }))
338+ assert .Equal (t , "original\n " , cli .OutBuffer ().String ())
339+ assert .Equal (t , "Successfully created context \" original\" \n " , cli .ErrBuffer ().String ())
322340
323341 cli .SetCurrentContext ("original" )
324342
325343 for _ , c := range cases {
326344 t .Run (c .name , func (t * testing.T ) {
345+ cli .ResetOutputBuffers ()
327346 err := RunCreate (cli , & CreateOptions {
328347 Name : c .name ,
329348 Description : c .description ,
330349 DefaultStackOrchestrator : c .orchestrator ,
331350 })
332351 assert .NilError (t , err )
352+ assert .Equal (t , c .name + "\n " , cli .OutBuffer ().String ())
353+ assert .Equal (t , fmt .Sprintf ("Successfully created context %q\n " , c .name ), cli .ErrBuffer ().String ())
333354 newContext , err := cli .ContextStore ().GetMetadata (c .name )
334355 assert .NilError (t , err )
335356 newContextTyped , err := command .GetDockerContext (newContext )
0 commit comments