package config

import (
	"testing"
)

func TestLoadCommon_Defaults(t *testing.T) {
	t.Setenv("BA_ENV", "")
	c, err := LoadCommon("ingestd")
	if err != nil {
		t.Fatal(err)
	}
	if c.Env != "dev" {
		t.Fatalf("default env: want dev, got %q", c.Env)
	}
	if c.ServiceName != "ingestd" {
		t.Fatalf("service name: got %q", c.ServiceName)
	}
	if c.ShutdownGrace.Seconds() != 15 {
		t.Fatalf("shutdown grace default: got %v", c.ShutdownGrace)
	}
}

func TestLoadCommon_BadEnv(t *testing.T) {
	t.Setenv("BA_ENV", "qa")
	_, err := LoadCommon("ingestd")
	if err == nil {
		t.Fatal("expected error for bad env")
	}
}

func TestLoadIngestd_Defaults(t *testing.T) {
	c, err := LoadIngestd()
	if err != nil {
		t.Fatal(err)
	}
	if c.MaxPayloadBytes != 256*1024 {
		t.Fatalf("max payload: %d", c.MaxPayloadBytes)
	}
	if c.RateLimitPerSource != 100 {
		t.Fatalf("rate limit per source: %d", c.RateLimitPerSource)
	}
}
