Skip to content

Commit

Permalink
Merge pull request #375 from IBM-Cloud/dev
Browse files Browse the repository at this point in the history
SDK Release 1.1.0
  • Loading branch information
Aerex authored Jun 7, 2023
2 parents 01bf208 + d9b96d6 commit 14d2e08
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 74 deletions.
16 changes: 5 additions & 11 deletions bluemix/configuration/config_helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import (
"github.com/stretchr/testify/assert"
)

// import (
// "io/ioutil"
// "os"
// "path/filepath"
// "testing"

// "github.com/stretchr/testify/assert"
// "github.ibm.com/bluemix-cli-release/build/src/github.ibm.com/Bluemix/bluemix-cli-common/file_helpers"
// )

func captureAndPrepareEnv(a *assert.Assertions) ([]string, string) {
env := os.Environ()

Expand All @@ -30,7 +20,11 @@ func captureAndPrepareEnv(a *assert.Assertions) ([]string, string) {
os.Unsetenv("IBMCLOUD_HOME")
os.Unsetenv("BLUEMIX_HOME")
os.Setenv("HOME", userHome)

// UserHomeDir() uses HOMEDRIVE + HOMEPATH for windows
if os.Getenv("OS") == "Windows_NT" {
// ioutil.TempDir has the drive letter in the path, so we need to remove it when we set HOMEDRIVE
os.Setenv("HOMEPATH", strings.Replace(userHome, os.Getenv("HOMEDRIVE"), "", -1))
}
a.NoError(os.RemoveAll(userHome))

return env, userHome
Expand Down
2 changes: 0 additions & 2 deletions bluemix/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
)

func TestGet(t *testing.T) {
assert.Empty(t, EnvTrace.Get())

os.Setenv("IBMCLOUD_TRACE", "true")
assert.Equal(t, "true", EnvTrace.Get())

Expand Down
16 changes: 16 additions & 0 deletions bluemix/terminal/table.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package terminal

import (
"encoding/csv"
"fmt"
"io"
"strings"

. "github.com/IBM-Cloud/ibm-cloud-cli-sdk/i18n"
"github.com/mattn/go-runewidth"
)

Expand All @@ -18,6 +20,7 @@ type Table interface {
Add(row ...string)
Print()
PrintJson()
PrintCsv() error
}

type PrintableTable struct {
Expand Down Expand Up @@ -157,3 +160,16 @@ func (t *PrintableTable) PrintJson() {
// mimic behavior of Print()
t.rows = [][]string{}
}

func (t *PrintableTable) PrintCsv() error {
csvwriter := csv.NewWriter(t.writer)
err := csvwriter.Write(t.headers)
if err != nil {
return fmt.Errorf(T("Failed, header could not convert to csv format"), err.Error())
}
err = csvwriter.WriteAll(t.rows)
if err != nil {
return fmt.Errorf(T("Failed, rows could not convert to csv format"), err.Error())
}
return nil
}
45 changes: 45 additions & 0 deletions bluemix/terminal/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package terminal_test

import (
"bytes"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -92,3 +93,47 @@ func TestNotEnoughRowEntiresJson(t *testing.T) {
assert.Contains(t, buf.String(), "\"column_1\": \"row1\"")
assert.Contains(t, buf.String(), "\"column_1\": \"\"")
}

func TestPrintCsvSimple(t *testing.T) {
buf := bytes.Buffer{}
testTable := NewTable(&buf, []string{"col1", "col2"})
testTable.Add("row1-col1", "row1-col2")
testTable.Add("row2-col1", "row2-col2")
err := testTable.PrintCsv()
assert.Equal(t, err, nil)
assert.Contains(t, buf.String(), "col1,col2")
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
assert.Contains(t, buf.String(), "row2-col1,row2-col2")
}

func TestNotEnoughColPrintCsv(t *testing.T) {
buf := bytes.Buffer{}
testTable := NewTable(&buf, []string{"", "col2"})
testTable.Add("row1-col1", "row1-col2")
testTable.Add("row2-col1", "row2-col2")
err := testTable.PrintCsv()
assert.Equal(t, err, nil)
assert.Contains(t, buf.String(), ",col2")
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
assert.Contains(t, buf.String(), "row2-col1,row2-col2")
}

func TestNotEnoughRowPrintCsv(t *testing.T) {
buf := bytes.Buffer{}
testTable := NewTable(&buf, []string{"col1", "col2"})
testTable.Add("row1-col1", "row1-col2")
testTable.Add("row2-col1", "")
err := testTable.PrintCsv()
assert.Equal(t, err, nil)
assert.Contains(t, buf.String(), "col1,col2")
assert.Contains(t, buf.String(), "row1-col1,row1-col2")
assert.Contains(t, buf.String(), "row2-col1,")
}

func TestEmptyTable(t *testing.T) {
buf := bytes.Buffer{}
testTable := NewTable(&buf, []string{})
err := testTable.PrintCsv()
assert.Equal(t, err, nil)
assert.Equal(t, len(strings.TrimSpace(buf.String())), 0)
}
2 changes: 1 addition & 1 deletion bluemix/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bluemix
import "fmt"

// Version is the SDK version
var Version = VersionType{Major: 1, Minor: 0, Build: 3}
var Version = VersionType{Major: 1, Minor: 1, Build: 0}

// VersionType describe version info
type VersionType struct {
Expand Down
1 change: 1 addition & 0 deletions common/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *Client) DoWithContext(ctx context.Context, r *Request, respV interface{
client = http.DefaultClient
}

req.Close = true
resp, err := client.Do(req)
if err != nil {
return resp, err
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886
github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309
github.com/gofrs/flock v0.8.1
github.com/mattn/go-colorable v0.0.0-20160210001857-9fdad7c47650
github.com/mattn/go-runewidth v0.0.0-20151118072159-d96d1bd051f2
github.com/nicksnyder/go-i18n/v2 v2.2.0
Expand All @@ -22,10 +23,10 @@ require (
require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.7.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts=
github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "FEHLGESCHLAGEN"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "FAILED"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
"id": "FAILED",
"translation": "ERROR"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "ECHEC"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "NON RIUSCITO"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "失敗"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "실패"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "COM FALHA"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.zh_Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "失败"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
8 changes: 8 additions & 0 deletions i18n/resources/all.zh_Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"id": "FAILED",
"translation": "失敗"
},
{
"id": "Failed, header could not convert to csv format",
"translation": "Failed, header could not convert to csv format"
},
{
"id": "Failed, rows could not convert to csv format",
"translation": "Failed, rows could not convert to csv format"
},
{
"id": "Invalid grant type: ",
"translation": "Invalid grant type: "
Expand Down
Loading

0 comments on commit 14d2e08

Please sign in to comment.