github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/command_test.go (about)

     1  // Copyright (C) 2015 Scaleway. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE.md file.
     4  
     5  // Golang structs for scw commands
     6  package commands
     7  
     8  import (
     9  	"fmt"
    10  	"os"
    11  	"testing"
    12  
    13  	"github.com/scaleway/scaleway-cli/pkg/api"
    14  	"github.com/scaleway/scaleway-cli/pkg/scwversion"
    15  	"github.com/stretchr/testify/assert"
    16  )
    17  
    18  func testCommandContext() CommandContext {
    19  	apiClient, err := api.NewScalewayAPI("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", scwversion.UserAgent(), "")
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	ctx := CommandContext{
    25  		Streams: Streams{
    26  			Stdin:  os.Stdin,
    27  			Stdout: os.Stdout,
    28  			Stderr: os.Stderr,
    29  		},
    30  		Env: []string{
    31  			"HOME" + os.Getenv("HOME"),
    32  		},
    33  		RawArgs: []string{},
    34  		API:     apiClient,
    35  	}
    36  	return ctx
    37  }
    38  
    39  func ExampleCommandContext() {
    40  	apiClient, err := api.NewScalewayAPI("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", scwversion.UserAgent(), "")
    41  	if err != nil {
    42  		panic(err)
    43  	}
    44  
    45  	ctx := CommandContext{
    46  		Streams: Streams{
    47  			Stdin:  os.Stdin,
    48  			Stdout: os.Stdout,
    49  			Stderr: os.Stderr,
    50  		},
    51  		Env: []string{
    52  			"HOME" + os.Getenv("HOME"),
    53  		},
    54  		RawArgs: []string{},
    55  		API:     apiClient,
    56  	}
    57  
    58  	// Do stuff
    59  	fmt.Println(ctx)
    60  }
    61  
    62  func TestCommandContext_Getenv(t *testing.T) {
    63  	ctx := testCommandContext()
    64  	assert.Equal(t, ctx.Getenv("HOME"), os.Getenv("HOME"))
    65  	assert.Equal(t, ctx.Getenv("DONTEXISTS"), "")
    66  }