Skip to content

Commit

Permalink
Update tests structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nasermirzaei89 committed Feb 24, 2024
1 parent 098eab5 commit bd3359d
Show file tree
Hide file tree
Showing 25 changed files with 802 additions and 483 deletions.
34 changes: 21 additions & 13 deletions float32_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,35 @@ func TestGetFloat32Slice(t *testing.T) {
}

func TestMustGetFloat32Slice(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
t.Run("MustGetAbsentFloat32Slice", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
})
})

expected := []float32{31.02, 32.33, 33.33}
t.Run("MustGetValidFloat32Slice", func(t *testing.T) {
expected := []float32{31.02, 32.33, 33.33}

t.Setenv("V1", "31.02,32.33,33.33")
t.Setenv("V1", "31.02,32.33,33.33")

res := env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
})

t.Setenv("V1", "1.2,2.3,Three")
t.Run("MustGetInvalidFloat32Slice", func(t *testing.T) {
t.Setenv("V1", "1.2,2.3,Three")

assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
})
})

expected = []float32{}
t.Run("MustGetEmptyFloat32Slice", func(t *testing.T) {
expected := make([]float32, 0)

t.Setenv("V1", "")
t.Setenv("V1", "")

res = env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
})
}
68 changes: 42 additions & 26 deletions float64_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,67 @@ import (
func TestGetFloat64Slice(t *testing.T) {
def := []float64{21.2, 22.3}

res := env.GetFloat64Slice("V1", def)
assert.Equal(t, def, res)
t.Run("GetAbsentFloat64SliceWithDefault", func(t *testing.T) {
res := env.GetFloat64Slice("V1", def)
assert.Equal(t, def, res)
})

expected := []float64{31.02, 32.33, 33.33}
t.Run("GetValidFloat64SliceWithDefault", func(t *testing.T) {
expected := []float64{31.02, 32.33, 33.33}

t.Setenv("V1", "31.02,32.33,33.33")
t.Setenv("V1", "31.02,32.33,33.33")

res = env.GetFloat64Slice("V1", def)
assert.Equal(t, expected, res)
res := env.GetFloat64Slice("V1", def)
assert.Equal(t, expected, res)
})

t.Setenv("V1", "1.2,2.3,Three")
t.Run("GetInvalidFloat64SliceWithDefault", func(t *testing.T) {
t.Setenv("V1", "1.2,2.3,Three")

res = env.GetFloat64Slice("V1", def)
assert.Equal(t, def, res)
res := env.GetFloat64Slice("V1", def)
assert.Equal(t, def, res)
})

expected = []float64{}
t.Run("GetEmptyFloat64SliceWithDefault", func(t *testing.T) {
expected := make([]float64, 0)

t.Setenv("V1", "")
t.Setenv("V1", "")

res = env.GetFloat64Slice("V1", def)
assert.Equal(t, expected, res)
res := env.GetFloat64Slice("V1", def)
assert.Equal(t, expected, res)
})
}

func TestMustGetFloat64Slice(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat64Slice("V1")
t.Run("MustGetAbsentFloat64Slice", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat64Slice("V1")
})
})

expected := []float64{31.02, 32.33, 33.33}
t.Run("MustGetValidFloat64Slice", func(t *testing.T) {
expected := []float64{31.02, 32.33, 33.33}

t.Setenv("V1", "31.02,32.33,33.33")
t.Setenv("V1", "31.02,32.33,33.33")

res := env.MustGetFloat64Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetFloat64Slice("V1")
assert.Equal(t, expected, res)
})

t.Setenv("V1", "1.2,2.3,Three")
t.Run("MustGetInvalidFloat64Slice", func(t *testing.T) {
t.Setenv("V1", "1.2,2.3,Three")

assert.Panics(t, func() {
env.MustGetFloat64Slice("V1")
assert.Panics(t, func() {
env.MustGetFloat64Slice("V1")
})
})

expected = []float64{}
t.Run("MustGetEmptyFloat64Slice", func(t *testing.T) {
expected := make([]float64, 0)

t.Setenv("V1", "")
t.Setenv("V1", "")

res = env.MustGetFloat64Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetFloat64Slice("V1")
assert.Equal(t, expected, res)
})
}
44 changes: 28 additions & 16 deletions float64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,45 @@ import (
func TestGetFloat64(t *testing.T) {
def := 12.5

res := env.GetFloat64("V1", def)
assert.InDelta(t, def, res, 0)
t.Run("GetAbsentFloat64WithDefault", func(t *testing.T) {
res := env.GetFloat64("V1", def)
assert.InDelta(t, def, res, 0)
})

t.Setenv("V1", "invalid")
t.Run("GetInvalidFloat64WithDefault", func(t *testing.T) {
t.Setenv("V1", "invalid")

res = env.GetFloat64("V1", def)
assert.InDelta(t, def, res, 0)
res := env.GetFloat64("V1", def)
assert.InDelta(t, def, res, 0)
})

t.Setenv("V1", "14.5")
t.Run("GetValidFloat64WithDefault", func(t *testing.T) {
t.Setenv("V1", "14.5")

res = env.GetFloat64("V1", def)
assert.InDelta(t, 14.5, res, 0)
res := env.GetFloat64("V1", def)
assert.InDelta(t, 14.5, res, 0)
})
}

func TestMustGetFloat64(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat64("V1")
t.Run("MustGetAbsentFloat64", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat64("V1")
})
})

assert.Panics(t, func() {
t.Setenv("V1", "invalid")
t.Run("MustGetInvalidFloat64", func(t *testing.T) {
assert.Panics(t, func() {
t.Setenv("V1", "invalid")

env.MustGetFloat64("V1")
env.MustGetFloat64("V1")
})
})

t.Setenv("V1", "14.5")
t.Run("MustGetValidFloat64", func(t *testing.T) {
t.Setenv("V1", "14.5")

res := env.MustGetFloat64("V1")
assert.InDelta(t, 14.5, res, 0)
res := env.MustGetFloat64("V1")
assert.InDelta(t, 14.5, res, 0)
})
}
3 changes: 3 additions & 0 deletions generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ func TestGet(t *testing.T) {
res := env.Get("V1", def)
assert.Equal(t, def, res)
})

t.Run("GetValidUIntSliceWithDefault", func(t *testing.T) {
expected := []uint{31, 32, 33}

Expand All @@ -565,12 +566,14 @@ func TestGet(t *testing.T) {
res := env.Get("V1", def)
assert.Equal(t, expected, res)
})

t.Run("GetInvalidUIntSliceWithDefault", func(t *testing.T) {
t.Setenv("V1", "1,2,Three")

res := env.Get("V1", def)
assert.Equal(t, def, res)
})

t.Run("GetEmptyUIntSliceWithDefault", func(t *testing.T) {
expected := make([]uint, 0)

Expand Down
68 changes: 42 additions & 26 deletions int16_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,67 @@ import (
func TestGetInt16Slice(t *testing.T) {
def := []int16{21, 22}

res := env.GetInt16Slice("V1", def)
assert.Equal(t, def, res)
t.Run("GetAbsentInt16SliceWithDefault", func(t *testing.T) {
res := env.GetInt16Slice("V1", def)
assert.Equal(t, def, res)
})

expected := []int16{31, 32, 33}
t.Run("GetValidInt16SliceWithDefault", func(t *testing.T) {
expected := []int16{31, 32, 33}

t.Setenv("V1", "31,32,33")
t.Setenv("V1", "31,32,33")

res = env.GetInt16Slice("V1", def)
assert.Equal(t, expected, res)
res := env.GetInt16Slice("V1", def)
assert.Equal(t, expected, res)
})

t.Setenv("V1", "1,2,Three")
t.Run("GetInvalidInt16SliceWithDefault", func(t *testing.T) {
t.Setenv("V1", "1,2,Three")

res = env.GetInt16Slice("V1", def)
assert.Equal(t, def, res)
res := env.GetInt16Slice("V1", def)
assert.Equal(t, def, res)
})

expected = []int16{}
t.Run("GetEmptyInt16SliceWithDefault", func(t *testing.T) {
expected := make([]int16, 0)

t.Setenv("V1", "")
t.Setenv("V1", "")

res = env.GetInt16Slice("V1", def)
assert.Equal(t, expected, res)
res := env.GetInt16Slice("V1", def)
assert.Equal(t, expected, res)
})
}

func TestMustGetInt16Slice(t *testing.T) {
assert.Panics(t, func() {
env.MustGetInt16Slice("V1")
t.Run("MustGetAbsentInt16Slice", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetInt16Slice("V1")
})
})

expected := []int16{31, 32, 33}
t.Run("MustGetValidInt16Slice", func(t *testing.T) {
expected := []int16{31, 32, 33}

t.Setenv("V1", "31,32,33")
t.Setenv("V1", "31,32,33")

res := env.MustGetInt16Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetInt16Slice("V1")
assert.Equal(t, expected, res)
})

t.Setenv("V1", "1,2,Three")
t.Run("MustGetInvalidInt16Slice", func(t *testing.T) {
t.Setenv("V1", "1,2,Three")

assert.Panics(t, func() {
env.MustGetInt16Slice("V1")
assert.Panics(t, func() {
env.MustGetInt16Slice("V1")
})
})

expected = []int16{}
t.Run("MustGetEmptyInt16Slice", func(t *testing.T) {
expected := make([]int16, 0)

t.Setenv("V1", "")
t.Setenv("V1", "")

res = env.MustGetInt16Slice("V1")
assert.Equal(t, expected, res)
res := env.MustGetInt16Slice("V1")
assert.Equal(t, expected, res)
})
}
46 changes: 28 additions & 18 deletions int16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,45 @@ import (
func TestGetInt16(t *testing.T) {
def := int16(12)

res := env.GetInt16("V1", def)
assert.Equal(t, def, res)

t.Setenv("V1", "invalid")

res = env.GetInt16("V1", def)
t.Run("GetAbsentInt16WithDefault", func(t *testing.T) {
res := env.GetInt16("V1", def)
assert.Equal(t, def, res)
})

assert.Equal(t, def, res)
t.Run("GetInvalidInt16WithDefault", func(t *testing.T) {
t.Setenv("V1", "invalid")

t.Setenv("V1", "14")
res := env.GetInt16("V1", def)
assert.Equal(t, def, res)
})

res = env.GetInt16("V1", def)
t.Run("GetValidInt16WithDefault", func(t *testing.T) {
t.Setenv("V1", "14")

assert.Equal(t, int16(14), res)
res := env.GetInt16("V1", def)
assert.Equal(t, int16(14), res)
})
}

func TestMustGetInt16(t *testing.T) {
assert.Panics(t, func() {
env.MustGetInt16("V1")
t.Run("MustGetAbsentInt16", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetInt16("V1")
})
})

assert.Panics(t, func() {
t.Setenv("V1", "invalid")
t.Run("MustGetInvalidInt16", func(t *testing.T) {
assert.Panics(t, func() {
t.Setenv("V1", "invalid")

env.MustGetInt16("V1")
env.MustGetInt16("V1")
})
})

t.Setenv("V1", "14")
t.Run("MustGetValidInt16", func(t *testing.T) {
t.Setenv("V1", "14")

res := env.MustGetInt16("V1")
assert.Equal(t, int16(14), res)
res := env.MustGetInt16("V1")
assert.Equal(t, int16(14), res)
})
}
Loading

0 comments on commit bd3359d

Please sign in to comment.