Skip to content

Commit

Permalink
test: 💍 improved coverage of helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
StanGirard committed Aug 3, 2022
1 parent 7d45d37 commit 7288b81
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions internal/helpers/interfaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package helpers

import (
"reflect"
"testing"
)

func TestConvertStringToInterface(t *testing.T) {
array := [][]string{
[]string{"1", "2", "3"},
[]string{"4", "5", "6"},
}
expected := [][]interface{}{
[]interface{}{"1", "2", "3"},
[]interface{}{"4", "5", "6"},
}
actual := ConvertStringToInterface(array)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
12 changes: 11 additions & 1 deletion internal/helpers/interval_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package helpers

import "testing"
import (
"testing"
"time"
)

func TestParseInterval(t *testing.T) {
interval, err := ParseInterval("2020-01-01:2020-01-02")
Expand All @@ -12,3 +15,10 @@ func TestParseInterval(t *testing.T) {
t.Errorf("Invalid interval")
}
}

func TestDaysInterval(t *testing.T) {
interval := DaysInterval(1)
if interval.Start != time.Now().AddDate(0, 0, -2).Format("2006-01-02") || interval.End != time.Now().AddDate(0, 0, -1).Format("2006-01-02") {
t.Errorf("Invalid interval")
}
}
9 changes: 9 additions & 0 deletions internal/helpers/numbers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package helpers

import "testing"

func TestFloat2Decimal(t *testing.T) {
if float2Decimal(1.2345) != "1.23" {
t.Errorf("Expected 1.23, got %s", float2Decimal(1.2345))
}
}

0 comments on commit 7288b81

Please sign in to comment.