get rid of global variables, makes testing way easier

This commit is contained in:
2022-10-19 12:44:19 +02:00
parent 399620de98
commit 1e36c148ff
11 changed files with 184 additions and 283 deletions

View File

@@ -19,6 +19,7 @@ package lib
import (
"fmt"
"github.com/tlinden/tablizer/cfg"
"testing"
)
@@ -68,9 +69,8 @@ func TestCompare(t *testing.T) {
for _, tt := range tests {
testname := fmt.Sprintf("compare-mode-%s-a-%s-b-%s-desc-%t", tt.mode, tt.a, tt.b, tt.desc)
t.Run(testname, func(t *testing.T) {
SortMode = tt.mode
SortDescending = tt.desc
got := compare(tt.a, tt.b)
c := cfg.Config{SortMode: tt.mode, SortDescending: tt.desc}
got := compare(&c, tt.a, tt.b)
if got != tt.want {
t.Errorf("got %t, want %t", got, tt.want)
}