Skip to content

Commit

Permalink
Added test cases for helper methods
Browse files Browse the repository at this point in the history
Signed-off-by: mabhi <[email protected]>
  • Loading branch information
mabhi committed Oct 16, 2023
1 parent 26c3ebd commit f5371f9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
83 changes: 83 additions & 0 deletions pkg/blockstorage/helper_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
package blockstorage

import (
. "gopkg.in/check.v1"
)

type HelperSuite struct{}

var _ = Suite(&HelperSuite{})

func (s *HelperSuite) SetUpSuite(c *C) {
}

func (h *HelperSuite) TestStringSlice(c *C) {
source := []string{"test1", "test2"}
target := StringSlice(&source)
c.Assert(target[0], Equals, source[0])
c.Assert(target[1], Equals, source[1])
}

func (s *HelperSuite) TestStringSlicePtr(c *C) {
source := []string{"test1", "test2"}
res := StringSlicePtr(source)
target := *res
c.Assert(target[0], Equals, source[0])
c.Assert(target[1], Equals, source[1])
}

func (s *HelperSuite) TestSliceStringPtr(c *C) {
source := []string{"test1", "test2"}
res := SliceStringPtr(source)
for i, elePtr := range res {
var target = *elePtr
c.Assert(target, Equals, source[i])
}
}

func (s *HelperSuite) TestBoolFromPtr(c *C) {
source := true
target := Bool(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestBoolToPtr(c *C) {
source := true
target := BoolPtr(source)
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestIntFromPtr(c *C) {
source := 1
target := Int(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestIntToPtr(c *C) {
source := 1
target := IntPtr(source)
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestFloat32FromPtr(c *C) {
source := float32(1)
target := Float32(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestFloat32ToPtr(c *C) {
source := float32(1)
target := Float32Ptr(source)
c.Assert(*target, Equals, source)
}

func (s *HelperSuite) TestStringFromPtr(c *C) {
source := "test"
target := String(&source)
c.Assert(target, Equals, source)
}

func (s *HelperSuite) TestStringToPtr(c *C) {
source := "test"
target := StringPtr(source)
c.Assert(*target, Equals, source)
}
2 changes: 1 addition & 1 deletion pkg/blockstorage/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func Float32Ptr(i float32) *float32 {
return &i
}

// Float64 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
// ToFloat64 returns an int value for the passed int pointer. It returns 0.0 if the pointer is nil.
func Float64(i *float64) float64 {
if i != nil {
return *i
Expand Down

0 comments on commit f5371f9

Please sign in to comment.