From d1236ebf4f27c513a6598c58b28eab585b6e942f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 25 Apr 2026 13:44:36 -0700 Subject: [PATCH] parquet_pushdown(M0): cover daemon Config validation, especially connector-trusted gating The connector-trusted trust mode is the dev-only escape hatch and must require both -trust=connector-trusted *and* -dev.connector_trusted_ack. The latter is intentionally awkward to flip so an operator cannot disable catalog validation by accident. Add unit tests covering: default ok, port range, missing filer addresses, connector-trusted without ack rejected, connector-trusted with ack accepted, unknown trust modes rejected, and that the error message names the ack flag so the operator knows how to proceed. --- weed/parquet_pushdown/daemon/config_test.go | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 weed/parquet_pushdown/daemon/config_test.go diff --git a/weed/parquet_pushdown/daemon/config_test.go b/weed/parquet_pushdown/daemon/config_test.go new file mode 100644 index 000000000..84defadfe --- /dev/null +++ b/weed/parquet_pushdown/daemon/config_test.go @@ -0,0 +1,76 @@ +package daemon + +import ( + "strings" + "testing" + + "github.com/seaweedfs/seaweedfs/weed/parquet_pushdown" + "github.com/seaweedfs/seaweedfs/weed/pb" +) + +func baseConfig() Config { + return Config{ + IP: "127.0.0.1", + Port: 18888, + FilerAddresses: []pb.ServerAddress{"localhost:8888"}, + Version: "test", + } +} + +func TestConfig_ValidateOK(t *testing.T) { + c := baseConfig() + if err := c.Validate(); err != nil { + t.Fatalf("expected ok, got %v", err) + } + if c.TrustMode != parquet_pushdown.TrustModeCatalogValidated { + t.Errorf("default trust mode = %q, want %q", c.TrustMode, parquet_pushdown.TrustModeCatalogValidated) + } +} + +func TestConfig_RejectsBadPort(t *testing.T) { + c := baseConfig() + c.Port = 0 + if err := c.Validate(); err == nil { + t.Fatal("expected error for port=0") + } + c.Port = 70000 + if err := c.Validate(); err == nil { + t.Fatal("expected error for port>65535") + } +} + +func TestConfig_RequiresFiler(t *testing.T) { + c := baseConfig() + c.FilerAddresses = nil + if err := c.Validate(); err == nil { + t.Fatal("expected error when filer addresses empty") + } +} + +// Connector-trusted is dev-only and must require an explicit +// acknowledgement flag. Operators must not be able to flip it on by +// passing -trust=connector-trusted alone. +func TestConfig_ConnectorTrustedRequiresAck(t *testing.T) { + c := baseConfig() + c.TrustMode = parquet_pushdown.TrustModeConnectorTrusted + err := c.Validate() + if err == nil { + t.Fatal("expected error when connector-trusted lacks ack") + } + if !strings.Contains(err.Error(), "connector_trusted_ack") { + t.Errorf("error %q should mention the ack flag", err.Error()) + } + + c.ConnectorTrustedAck = true + if err := c.Validate(); err != nil { + t.Fatalf("connector-trusted with ack should pass, got %v", err) + } +} + +func TestConfig_RejectsUnknownTrustMode(t *testing.T) { + c := baseConfig() + c.TrustMode = parquet_pushdown.TrustMode("nonsense") + if err := c.Validate(); err == nil { + t.Fatal("expected error for unknown trust mode") + } +}