Files
iotlcm/worker-svr/internal/worker/monthlyusage_config_test.go
T

40 lines
1.1 KiB
Go

package worker
import (
"context"
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg"
)
func TestMonthlyUsageScanStartupConfig(t *testing.T) {
old := g.Cfg().GetAdapter()
defer g.Cfg().SetAdapter(old)
for _, test := range []struct {
name, yaml string
concurrency int
invalid bool
}{
{"omitted", "{}", 4, false},
{"channel", "trafficUsageFullSync:\n producer:\n scanMode: channel\n scanConcurrency: 4", 4, false},
{"zero", "trafficUsageFullSync:\n producer:\n scanConcurrency: 0", 0, true},
{"negative", "trafficUsageFullSync:\n producer:\n scanConcurrency: -1", 0, true},
} {
t.Run(test.name, func(t *testing.T) {
adapter, err := gcfg.NewAdapterContent(test.yaml)
if err != nil {
t.Fatal(err)
}
g.Cfg().SetAdapter(adapter)
config, err := loadMonthlyUsageProducerConfig(context.Background())
if (err != nil) != test.invalid {
t.Fatalf("config=%+v err=%v", config, err)
}
if !test.invalid && config.ScanConcurrency != test.concurrency {
t.Fatalf("config=%+v", config)
}
})
}
}