Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

1.3 KB
Raw Blame
package s3api

import (
	"testing"

	"github.com/seaweedfs/seaweedfs/weed/util"
)

func TestAdvertisedHost(t *testing.T) {
	detected := util.DetectedHostAddress()

	for _, tc := range []struct {
		name   string
		ip     string
		bindIp string
		want   string
	}{
		{"advertised ip wins over wildcard bind", "localhost", "0.0.0.0", "localhost"},
		{"advertised ip wins over specific bind", "s3.example.com", "10.0.0.5", "s3.example.com"},
		{"bind ip used when no advertised ip", "", "10.0.0.5", "10.0.0.5"},
		{"ipv6 bind ip used when no advertised ip", "", "2001:db8::1", "2001:db8::1"},
		{"wildcard bind falls back to detected", "", "0.0.0.0", detected},
		{"ipv6 wildcard bind falls back to detected", "", "::", detected},
		{"bracketed ipv6 wildcard bind falls back to detected", "", "[::]", detected},
		{"expanded ipv6 wildcard bind falls back to detected", "", "0:0:0:0:0:0:0:0", detected},
		{"wildcard advertised ip falls back to bind ip", "0.0.0.0", "10.0.0.5", "10.0.0.5"},
		{"wildcard advertised ip and bind fall back to detected", "::", "0.0.0.0", detected},
		{"empty falls back to detected", "", "", detected},
	} {
		t.Run(tc.name, func(t *testing.T) {
			option := &S3ApiServerOption{Ip: tc.ip, BindIp: tc.bindIp}
			if got := option.advertisedHost(); got != tc.want {
				t.Errorf("advertisedHost() = %q, want %q", got, tc.want)
			}
		})
	}
}