diff --git a/client_test.go b/client_test.go index a51e29f..3f9f315 100644 --- a/client_test.go +++ b/client_test.go @@ -1,40 +1,50 @@ -package main +package main_test import ( "io" "os" "testing" + "github.com/devdinu/gcloud-client/command" + "github.com/devdinu/gcloud-client/gcloud" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) func TestClient(t *testing.T) { - cfg := Config{} + cfg := command.Config{Format: "json"} e := new(executorMock) - c := client{e} + client := gcloud.NewClient(e) f, err := os.Open("./testdata/reference.json") require.NoError(t, err) defer f.Close() - e.On("Execute", GetInstancesCmd(cfg)).Return(f, nil) + e.On("Execute", command.GetInstancesCmd(cfg)).Return(f, nil) - insts, err := c.getInstances(cfg) + insts, err := client.GetInstances(cfg) require.NoError(t, err) - expectedInstance := instance{ - Name: "some-instance-name", - Zone: "https://www.googleapis.com/compute/v1/projects/some-cluster/zones/somezone-a", - NetworkInterfaces: []NetworkInterface{{NetworkIP: "10.11.12.13"}}, - Status: "RUNNING", + expectedInstance := gcloud.Instance{ + Name: "some-instance-name", + Zone: "https://www.googleapis.com/compute/v1/projects/some-cluster/zones/somezone-a", + NetworkInterfaces: []gcloud.NetworkInterface{ + { + NetworkIP: "10.11.12.13", + AccessConfigs: []gcloud.AccessConfig{ + {NatIP: "12.34.56.78", Name: "external-nat"}, + }, + }, + }, + Status: "RUNNING", } + e.AssertExpectations(t) assert.Equal(t, expectedInstance, insts[0]) } type executorMock struct{ mock.Mock } -func (m *executorMock) Execute(c Command) (io.Reader, error) { +func (m *executorMock) Execute(c command.Command) (io.Reader, error) { args := m.Called(c) return args.Get(0).(io.Reader), args.Error(1) } diff --git a/config/defaults.go b/config/defaults.go index f5df8da..8a7c26e 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -58,8 +58,6 @@ func loadDefaults(configFile string) (*Defaults, error) { return nil, fmt.Errorf("reading config file %s failed with error %v", configFile, err) } } - logger.Debugf("[Config] Loaded default config: %+v from file %s", appConfig, configFile) - return &appConfig, nil } diff --git a/gcloud/client.go b/gcloud/client.go index d9bef02..48eba79 100644 --- a/gcloud/client.go +++ b/gcloud/client.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "fmt" "io" "io/ioutil" "os" @@ -30,7 +31,7 @@ func (c Client) GetInstances(cfg command.Config) ([]Instance, error) { var insts []Instance err = json.NewDecoder(out).Decode(&insts) if err != nil { - return nil, err + return nil, fmt.Errorf("[Client] decoding error: %v", err) } return insts, nil } diff --git a/testdata/reference.json b/testdata/reference.json index 5183ba1..ec87456 100644 --- a/testdata/reference.json +++ b/testdata/reference.json @@ -49,7 +49,7 @@ "name": "nic0", "network": "https://www.googleapis.com/compute/v1/projects/some-cluster/global/networks/default", "networkIP": "10.11.12.13", - "subnetwork": "https://www.googleapis.com/compute/v1/projects/some-cluster/regions/somezone/subnetworks/default-subnet" + "subnetwork": "https://www.googleapis.com/compute/v1/projects/some-cluster/regions/somezone/subnetworks/default-subnet", "accessConfigs": [ { "name": "external-nat",