58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestDistributorListParsing(t *testing.T) {
|
|
c := &Config{Distributors: "srs-hls,cf,cdn"}
|
|
got := c.DistributorList()
|
|
if len(got) != 3 || got[0] != "srs-hls" {
|
|
t.Fatalf("unexpected distributors %v", got)
|
|
}
|
|
if got[1] != "cf" || got[2] != "cdn" {
|
|
t.Fatalf("unexpected order %v", got)
|
|
}
|
|
if c.CDNEnabled() {
|
|
t.Fatalf("should not be enabled without CDN_RTMP_URL")
|
|
}
|
|
// alias normalization
|
|
c2 := &Config{Distributors: "srs,cloudflare,cdn"}
|
|
got2 := c2.DistributorList()
|
|
if got2[0] != "srs-hls" || got2[1] != "cf" {
|
|
t.Fatalf("alias normalize failed %v", got2)
|
|
}
|
|
}
|
|
|
|
func TestDistributorListDedup(t *testing.T) {
|
|
c := &Config{Distributors: "srs-hls,srs-hls,cf"}
|
|
got := c.DistributorList()
|
|
if len(got) != 2 {
|
|
t.Fatalf("want dedup 2, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestValidateCDNRequiresURLWhenEnabled(t *testing.T) {
|
|
c := &Config{Distributors: "cdn", CDNRTMPURL: ""}
|
|
if err := c.ValidateDistributors(); err == nil {
|
|
t.Fatal("expected error when cdn enabled without URL")
|
|
}
|
|
c2 := &Config{Distributors: "cdn", CDNRTMPURL: "rtmp://cdn.example.com/live"}
|
|
if err := c2.ValidateDistributors(); err != nil {
|
|
t.Fatalf("unexpected error %v", err)
|
|
}
|
|
c3 := &Config{Distributors: "srs-hls,cf", CDNRTMPURL: ""}
|
|
if err := c3.ValidateDistributors(); err != nil {
|
|
t.Fatalf("should not require CDN URL when cdn not in list, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestCDNEnabled(t *testing.T) {
|
|
c := &Config{CDNRTMPURL: ""}
|
|
if c.CDNEnabled() {
|
|
t.Fatal("empty should be disabled")
|
|
}
|
|
c2 := &Config{CDNRTMPURL: "rtmp://a/b"}
|
|
if !c2.CDNEnabled() {
|
|
t.Fatal("non-empty should be enabled")
|
|
}
|
|
}
|