2026-09-22 15:53:31 +02:00
|
|
|
package discover
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-22 16:09:44 +02:00
|
|
|
func TestCandidatesAreExactLabelsOnly(t *testing.T) {
|
2026-09-22 17:12:30 +02:00
|
|
|
got := candidates("assets.example.com")
|
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)
|
2026-09-22 15:53:31 +02:00
|
|
|
}
|
|
|
|
|
for _, c := range got {
|
|
|
|
|
if !validBucketName(c) {
|
|
|
|
|
t.Fatalf("invalid candidate %q", c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 17:28:41 +02:00
|
|
|
func TestValidAzureAccount(t *testing.T) {
|
|
|
|
|
for _, ok := range []string{"myaccount", "abc123", "a1b2c3d4e5f6g7h8i9j0k1l2"} {
|
|
|
|
|
if !validAzureAccount(ok) {
|
|
|
|
|
t.Fatalf("%q should be a valid Azure account name", ok)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, bad := range []string{"ab", "has-hyphen", "UPPER", "with.dot", "a1b2c3d4e5f6g7h8i9j0k1l2m3"} {
|
|
|
|
|
if validAzureAccount(bad) {
|
|
|
|
|
t.Fatalf("%q should be rejected as an Azure account name", bad)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 15:53:31 +02:00
|
|
|
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) {
|
2026-09-22 17:12:30 +02:00
|
|
|
d := New(Config{})
|
2026-09-22 15:53:31 +02:00
|
|
|
ts := d.targets("example")
|
2026-09-22 17:12:30 +02:00
|
|
|
if len(ts) != 2 {
|
|
|
|
|
t.Fatalf("got %d targets, want 2", len(ts))
|
2026-09-22 15:53:31 +02:00
|
|
|
}
|
2026-09-22 17:12:30 +02:00
|
|
|
var s3, gcs bool
|
2026-09-22 15:53:31 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-22 17:12:30 +02:00
|
|
|
if !s3 || !gcs {
|
|
|
|
|
t.Fatalf("missing targets: s3=%v gcs=%v (%v)", s3, gcs, ts)
|
2026-09-22 15:53:31 +02:00
|
|
|
}
|
|
|
|
|
}
|