basic testing and a few tweaks

This commit is contained in:
Greg Gauthier 2021-03-17 19:11:18 +00:00
parent 967337a938
commit b6b35d1000
4 changed files with 66 additions and 3 deletions

3
browser_test.go Normal file
View File

@ -0,0 +1,3 @@
package main

View File

@ -2,7 +2,6 @@ package main
import ( import (
"errors" "errors"
"fmt"
"log" "log"
"os" "os"
"strconv" "strconv"
@ -10,11 +9,11 @@ import (
"github.com/alyu/configparser" "github.com/alyu/configparser"
) )
//str2int
func str2int(strnum string) int { func str2int(strnum string) int {
i, err := strconv.Atoi(strnum) i, err := strconv.Atoi(strnum)
if err != nil { if err != nil {
fmt.Println(err) return 9999
os.Exit(2)
} }
return i return i
} }

60
config_test.go Normal file
View File

@ -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))
}
}

1
go.mod
View File

@ -5,4 +5,5 @@ go 1.16
require ( require (
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc
github.com/dixonwille/wmenu/v5 v5.1.0 github.com/dixonwille/wmenu/v5 v5.1.0
github.com/stretchr/testify v1.4.0
) )