Files
bucketeer/internal/discover/discover_test.go
T

56 lines
1.4 KiB
Go
Raw Normal View History

package discover
import (
"strings"
"testing"
)
2026-09-22 16:09:44 +02:00
func TestCandidatesAreExactLabelsOnly(t *testing.T) {
got := candidates("assets.example.com", 200)
2026-09-22 16:09:44 +02:00
if len(got) != 2 || got[0] != "assets" || got[1] != "example" {
t.Fatalf("candidates = %v, want [assets example] (no fabricated names)", got)
}
for _, c := range got {
if !validBucketName(c) {
t.Fatalf("invalid candidate %q", c)
}
}
}
func TestBaseLabelsSkipsNoise(t *testing.T) {
got := baseLabels("www.example.com")
if len(got) != 1 || got[0] != "example" {
t.Fatalf("baseLabels = %v, want [example]", got)
}
if baseLabels("example") != nil {
t.Fatal("single label must yield no base")
}
}
func TestTargets(t *testing.T) {
d := New(Config{S3: true, GCS: true, DOSpaces: true, DORegions: []string{"nyc3"}})
ts := d.targets("example")
if len(ts) != 3 {
t.Fatalf("got %d targets, want 3", len(ts))
}
var s3, gcs, do bool
for _, tg := range ts {
switch {
case strings.Contains(tg.URL, "example.s3.amazonaws.com/?list-type=2"):
s3 = true
case strings.Contains(tg.URL, "storage.googleapis.com/example"):
gcs = true
case strings.Contains(tg.URL, "example.nyc3.digitaloceanspaces.com/?list-type=2"):
do = true
}
}
if !s3 || !gcs || !do {
t.Fatalf("missing targets: s3=%v gcs=%v do=%v (%v)", s3, gcs, do, ts)
}
}
func TestMaxPerDomain(t *testing.T) {
2026-09-22 16:09:44 +02:00
if got := candidates("example.com", 5); len(got) > 5 {
t.Fatalf("MaxPerDomain not honored: got %d", len(got))
}
}