package api import ( "testing" "pilotvault/apiserver/internal/config" ) func TestStorageSameExceptSecret(t *testing.T) { a := storageSettings{Enabled: true, Bucket: "pilotvault", Region: "us-east-1", Endpoint: "http://seaweedfs:8333", AccessKey: "k", Secret: "s1", ForcePathStyle: true} // PocketBase masks the secret on read, so a differing secret alone matches. b := a b.Secret = "******" if !a.sameExceptSecret(b) { t.Fatal("secret-only difference should compare equal") } b = a b.Endpoint = "http://seaweedfs-s3:8333" if a.sameExceptSecret(b) { t.Fatal("endpoint change should force a write") } if a.sameExceptSecret(storageSettings{}) { t.Fatal("a fresh PocketBase (S3 off) should force a write") } } func TestStorageConfigured(t *testing.T) { full := config.Config{S3Enabled: true, S3Bucket: "b", S3Endpoint: "http://e", S3AccessKey: "k", S3Secret: "s"} if !full.StorageConfigured() { t.Fatal("fully described bucket should be configured") } for name, mut := range map[string]func(*config.Config){ "disabled": func(c *config.Config) { c.S3Enabled = false }, "no endpoint": func(c *config.Config) { c.S3Endpoint = "" }, "no key": func(c *config.Config) { c.S3AccessKey = "" }, "no secret": func(c *config.Config) { c.S3Secret = "" }, } { c := full mut(&c) if c.StorageConfigured() { t.Errorf("%s: should not be configured", name) } } }