Skip to content

Commit

Permalink
Fix panics in ibms (#5839)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepikaDixit authored Jun 18, 2019
1 parent 9c7f8c1 commit 918ef18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pkg/blockstorage/ibm/client_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ func (s KubeTestIBMClient) TearDownSuite(c *C) {

func (s KubeTestIBMClient) TestIBMSecret(c *C) {
apiKey := os.Getenv(IBMApiKeyEnv)
os.Unsetenv(IBMApiKeyEnv)
err := os.Unsetenv(IBMApiKeyEnv)
c.Assert(err, IsNil)
defer os.Setenv(IBMApiKeyEnv, apiKey)
ibmCli, err := newClient(context.Background(), map[string]string{CfgSecretNameArgName: testSecretName})
defer ibmCli.Service.Close()
c.Assert(err, IsNil)
c.Assert(ibmCli, NotNil)
c.Assert(ibmCli.Service, NotNil)
defer ibmCli.Service.Close()
c.Assert(*ibmCli, FitsTypeOf, client{})
_, err = ibmCli.Service.SnapshotsList()
c.Assert(err, IsNil)
Expand Down
18 changes: 12 additions & 6 deletions pkg/blockstorage/ibm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,32 @@ func (s *ClientSuite) TestClient(c *C) {
c.Skip(fmt.Sprintf("Could not find env var %s with API key", IBMApiKeyEnv))
}
ibmCli, err := newClient(context.Background(), map[string]string{APIKeyArgName: apiKey})
defer ibmCli.Service.Close()
c.Assert(err, IsNil)
c.Assert(ibmCli, NotNil)
c.Assert(ibmCli.Service, NotNil)
defer ibmCli.Service.Close()
c.Assert(*ibmCli, FitsTypeOf, client{})
_, err = ibmCli.Service.SnapshotsList()
c.Assert(err, IsNil)
}

func (s *ClientSuite) TestDefaultLibConfig(c *C) {
if tomlPath, ok := os.LookupEnv(workAroundEnv); ok {
os.Setenv(LibDefCfgEnv, filepath.Dir(tomlPath))
err := os.Setenv(LibDefCfgEnv, filepath.Dir(tomlPath))
c.Assert(err, IsNil)
defer os.Unsetenv(LibDefCfgEnv)
} else {
c.Skip(workAroundEnv + " TOML path is not present")
}
apiKey := os.Getenv(IBMApiKeyEnv)
os.Unsetenv(IBMApiKeyEnv)
err := os.Unsetenv(IBMApiKeyEnv)
c.Assert(err, IsNil)
defer os.Setenv(IBMApiKeyEnv, apiKey)
ibmCli, err := newClient(context.Background(), make(map[string]string))
defer ibmCli.Service.Close()
c.Assert(err, IsNil)
c.Assert(ibmCli, NotNil)
c.Assert(ibmCli.Service, NotNil)
defer ibmCli.Service.Close()
c.Assert(*ibmCli, FitsTypeOf, client{})
}

Expand All @@ -71,11 +75,13 @@ func (s *ClientSuite) TestErrorsCases(c *C) {
ibmCli, err := newClient(context.Background(), map[string]string{CfgSecretNameArgName: "somename"})
c.Assert(err, NotNil)
c.Assert(ibmCli, IsNil)
os.Setenv(LibDefCfgEnv, "someboguspath")
err = os.Setenv(LibDefCfgEnv, "someboguspath")
c.Assert(err, IsNil)
ibmCli, err = newClient(context.Background(), make(map[string]string))
c.Assert(err, NotNil)
c.Assert(ibmCli, IsNil)
os.Setenv(LibDefCfgEnv, testBogusPath)
err = os.Setenv(LibDefCfgEnv, testBogusPath)
c.Assert(err, IsNil)
ibmCli, err = newClient(context.Background(), make(map[string]string))
c.Assert(err, NotNil)
c.Assert(ibmCli, IsNil)
Expand Down

0 comments on commit 918ef18

Please sign in to comment.