diff --git a/browser_test.go b/browser_test.go new file mode 100644 index 0000000..1110061 --- /dev/null +++ b/browser_test.go @@ -0,0 +1,3 @@ +package main + + diff --git a/config.go b/config.go index 020b0ce..ffef6d5 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,6 @@ package main import ( "errors" - "fmt" "log" "os" "strconv" @@ -10,11 +9,11 @@ import ( "github.com/alyu/configparser" ) +//str2int func str2int(strnum string) int { i, err := strconv.Atoi(strnum) if err != nil { - fmt.Println(err) - os.Exit(2) + return 9999 } return i } diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..6c46a6c --- /dev/null +++ b/config_test.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +//str2int +func Test_str2int(t *testing.T){ + t.Run("Testing normal integer:", teststr2intFunc("5", 5)) + t.Run("Testing large integer:", teststr2intFunc("4294967296",4294967296)) + t.Run("Testing negative integer:", teststr2intFunc("-5", -5)) + t.Run("Testing invalid input:", teststr2intFunc("a", 9999)) +} + +func teststr2intFunc(numstr string, expected int) func(*testing.T) { + return func(t *testing.T) { + if !assert.Equal(t, expected, str2int(numstr)) { + t.Error(fmt.Sprintf("%d does not equal %d", str2int(numstr), expected)) + } + } +} + +func Test_api(t *testing.T) { + expectedApi := "all.api.radio-browser.info" + api := api() + pass := assert.Equal(t, expectedApi, api) + if !pass { + t.Error(fmt.Sprintf("`%s does not match %s", api, expectedApi)) + } +} + +func Test_player(t *testing.T) { + expectedPlayer := "mpv" + player := player() + pass := assert.Equal(t, expectedPlayer, player) + if !pass { + t.Error(fmt.Sprintf("`%s does not match %s", player, expectedPlayer)) + } +} + +func Test_options(t *testing.T) { + expectedOptions := "--no-video" + options := options() + pass := assert.Equal(t, expectedOptions, options) + if !pass { + t.Error(fmt.Sprintf("`%s does not match %s", options, expectedOptions)) + } +} + +func Test_maxitems(t *testing.T) { + expectedMaxItems := 9999 + maxItems := maxitems() + pass := assert.Equal(t, expectedMaxItems, maxItems) + if !pass { + t.Error(fmt.Sprintf("`%d does not match %d", maxItems, expectedMaxItems)) + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index 125b23c..02ca223 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.16 require ( github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc github.com/dixonwille/wmenu/v5 v5.1.0 + github.com/stretchr/testify v1.4.0 )