add and fix tests
This commit is contained in:
24
cmd/any2anexoj-cli/localizer_test.go
Normal file
24
cmd/any2anexoj-cli/localizer_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestNewLocalizer(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
lang string
|
||||||
|
}{
|
||||||
|
{"english", "en"},
|
||||||
|
{"portuguese", "pt"},
|
||||||
|
{"english with region", "en-US"},
|
||||||
|
{"portuguese with region", "pt-BR"},
|
||||||
|
{"unknown language falls back to default", "!!"},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
_, err := NewLocalizer(tt.lang)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("want success call but failed: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -211,7 +211,7 @@ func TestAggregatorWriter_Items(t *testing.T) {
|
|||||||
aw := &internal.AggregatorWriter{}
|
aw := &internal.AggregatorWriter{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
for range 10 {
|
for range 5 {
|
||||||
item := internal.ReportItem{Symbol: "TEST"}
|
item := internal.ReportItem{Symbol: "TEST"}
|
||||||
if err := aw.Write(ctx, item); err != nil {
|
if err := aw.Write(ctx, item); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
@@ -226,6 +226,17 @@ func TestAggregatorWriter_Items(t *testing.T) {
|
|||||||
if count != 5 {
|
if count != 5 {
|
||||||
t.Errorf("expected for loop to stop at 5 items, got %d", count)
|
t.Errorf("expected for loop to stop at 5 items, got %d", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for range aw.Iter() {
|
||||||
|
count++
|
||||||
|
if count == 3 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count != 3 {
|
||||||
|
t.Errorf("expected for loop to stop at 3 items, got %d", count)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAggregatorWriter_ThreadSafety(t *testing.T) {
|
func TestAggregatorWriter_ThreadSafety(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user