From 5001adf17d6b44239250e1a220da41ef10398bc4 Mon Sep 17 00:00:00 2001 From: MudassarTariq Date: Sat, 24 Oct 2026 20:26:39 +0500 Subject: [PATCH 1/2] fix: patch HTTP/2 dependencies and cover transport regressions --- README.md | 4 + go.mod | 10 +- go.sum | 20 ++-- internal/ipgeolocation/http2_test.go | 150 +++++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 15 deletions(-) create mode 100644 internal/ipgeolocation/http2_test.go diff --git a/README.md b/README.md index 280a780..a648be8 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Column by column reference: [`docs/tables.md`](docs/tables.md). - Go 1.26.5 or later, to build the plugin binary - An IPGeolocation.io API key. The free Developer plan gives you 1,000 requests a day and covers the geolocation table. Sign up at [app.ipgeolocation.io/signup](https://app.ipgeolocation.io/signup). +Build release binaries with a patched Go toolchain: Go 1.26.10 or later on the +1.26 line, or Go 1.27.3 or later. Updating modules does not patch the standard +library embedded in an existing binary; rebuild and replace deployed binaries. + ## Quick Start ```bash diff --git a/go.mod b/go.mod index 4bc0ee9..6b5c0c1 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/cloudquery/plugin-sdk/v4 v4.96.3 github.com/rs/zerolog v1.35.1 github.com/stretchr/testify v1.12.1 + golang.org/x/net v0.60.0 golang.org/x/time v0.8.0 ) @@ -80,12 +81,11 @@ require ( go.yaml.in/yaml/v3 v3.0.5 // indirect go.yaml.in/yaml/v4 v4.0.0-rc.2 // indirect golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa // indirect - golang.org/x/mod v0.39.0 // indirect - golang.org/x/net v0.58.0 // indirect - golang.org/x/sync v0.22.0 // indirect - golang.org/x/sys v0.47.0 // indirect + golang.org/x/mod v0.41.0 // indirect + golang.org/x/sync v0.23.0 // indirect + golang.org/x/sys v0.48.0 // indirect golang.org/x/telemetry v0.0.0-20260811182544-a038080d80e5 // indirect - golang.org/x/text v0.41.0 // indirect + golang.org/x/text v0.42.0 // indirect golang.org/x/tools v0.49.0 // indirect golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d // indirect diff --git a/go.sum b/go.sum index 40762b1..991da17 100644 --- a/go.sum +++ b/go.sum @@ -201,19 +201,19 @@ go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s= go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk= golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM= -golang.org/x/mod v0.39.0 h1:UF5zwQdCRRUpHfyPwr7d4UrGiVeldIsogtzWVnczL74= -golang.org/x/mod v0.39.0/go.mod h1:bvIbwjQ0HUFFf5AKukeeYQG4ZBUG9yxQbR9aEweIwYY= -golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= -golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= -golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= -golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= +golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= +golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU= +golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= +golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= +golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= -golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= +golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/telemetry v0.0.0-20260811182544-a038080d80e5 h1:ZUSxONxc981v7AW7QUg+I9WwZzSTTJ019ENBYr5pV/Q= golang.org/x/telemetry v0.0.0-20260811182544-a038080d80e5/go.mod h1:LVehoXe41cL5SCVQilsV7Gg6BNG+Js6P9PhSbYTIUkQ= -golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= -golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= +golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= +golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI= diff --git a/internal/ipgeolocation/http2_test.go b/internal/ipgeolocation/http2_test.go new file mode 100644 index 0000000..3290800 --- /dev/null +++ b/internal/ipgeolocation/http2_test.go @@ -0,0 +1,150 @@ +package ipgeolocation + +import ( + "bytes" + "context" + "crypto/tls" + "encoding/json" + "io" + "net" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/net/http2" + "golang.org/x/net/http2/hpack" +) + +func TestClientHTTP2Requests(t *testing.T) { + server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, 2, r.ProtoMajor) + assert.Equal(t, "test-key", r.URL.Query().Get("apiKey")) + assert.Equal(t, "cq-http2-test", r.UserAgent()) + assert.Equal(t, "application/json", r.Header.Get("Accept")) + w.Header().Set("Content-Type", "application/json") + switch r.URL.Path { + case "/v3/ipgeo": + assert.Equal(t, http.MethodGet, r.Method) + assert.Equal(t, "1.1.1.1", r.URL.Query().Get("ip")) + assert.Equal(t, "security,abuse", r.URL.Query().Get("include")) + _, _ = w.Write([]byte(`{"ip":"1.1.1.1","location":{"country_name":"Australia"}}`)) + case "/v3/user-agent": + assert.Equal(t, http.MethodPost, r.Method) + assert.Equal(t, "application/json", r.Header.Get("Content-Type")) + var body map[string]string + assert.NoError(t, json.NewDecoder(r.Body).Decode(&body)) + assert.Equal(t, map[string]string{"uaString": "test-ua"}, body) + _, _ = w.Write([]byte(`{"user_agent_string":"test-ua","name":"TestBrowser"}`)) + default: + t.Errorf("unexpected request: %s", r.URL.Path) + w.WriteHeader(http.StatusNotFound) + } + })) + server.EnableHTTP2 = true + server.StartTLS() + t.Cleanup(server.Close) + + transport := &http2.Transport{ + TLSClientConfig: server.Client().Transport.(*http.Transport).TLSClientConfig.Clone(), + } + t.Cleanup(transport.CloseIdleConnections) + c, err := NewClient("test-key", + WithEndpoint(server.URL), + WithHTTPClient(&http.Client{Transport: transport, Timeout: 5 * time.Second}), + WithUserAgent("cq-http2-test"), + WithRetries(0), + ) + require.NoError(t, err) + + geo, err := c.GetIPGeolocation(context.Background(), "1.1.1.1", "security", "abuse") + require.NoError(t, err) + assert.Equal(t, "1.1.1.1", geo.IP) + assert.Equal(t, "Australia", geo.Location.CountryName) + + ua, err := c.GetUserAgent(context.Background(), "test-ua") + require.NoError(t, err) + assert.Equal(t, "test-ua", ua.UserAgentString) + assert.Equal(t, "TestBrowser", ua.Name) +} + +func TestHTTP2ResponseFraming(t *testing.T) { + for _, tc := range []struct { + name string + lengths []string + wantLengths []string + }{ + {name: "valid", lengths: []string{"2"}, wantLengths: []string{"2"}}, + {name: "conflicting", lengths: []string{"2", "1"}}, + } { + t.Run(tc.name, func(t *testing.T) { + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(t, err) + t.Cleanup(func() { _ = listener.Close() }) + serverDone := make(chan error, 1) + go func() { + serverDone <- func() error { + conn, err := listener.Accept() + if err != nil { + return err + } + defer conn.Close() + if err := conn.SetDeadline(time.Now().Add(5 * time.Second)); err != nil { + return err + } + preface := make([]byte, len(http2.ClientPreface)) + if _, err := io.ReadFull(conn, preface); err != nil { + return err + } + framer := http2.NewFramer(conn, conn) + if err := framer.WriteSettings(); err != nil { + return err + } + for { + frame, err := framer.ReadFrame() + if err != nil { + return err + } + if headers, ok := frame.(*http2.HeadersFrame); ok { + // Write raw fields: net/http sanitizes duplicate lengths before sending them. + var block bytes.Buffer + encoder := hpack.NewEncoder(&block) + if err := encoder.WriteField(hpack.HeaderField{Name: ":status", Value: "200"}); err != nil { + return err + } + for _, value := range tc.lengths { + if err := encoder.WriteField(hpack.HeaderField{Name: "content-length", Value: value}); err != nil { + return err + } + } + if err := framer.WriteHeaders(http2.HeadersFrameParam{ + StreamID: headers.StreamID, EndHeaders: true, BlockFragment: block.Bytes(), + }); err != nil { + return err + } + return framer.WriteData(headers.StreamID, true, []byte("{}")) + } + } + }() + }() + transport := &http2.Transport{ + AllowHTTP: true, + DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, network, addr) + }, + } + t.Cleanup(transport.CloseIdleConnections) + client := &http.Client{Transport: transport, Timeout: 5 * time.Second} + resp, err := client.Get("http://" + listener.Addr().String()) + require.NoError(t, err) + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + require.NoError(t, err) + assert.Equal(t, "{}", string(body)) + assert.Equal(t, tc.wantLengths, resp.Header.Values("Content-Length")) + require.NoError(t, <-serverDone) + }) + } +} From 842cd2f733a59e9ffb0c63a573f911f572373c33 Mon Sep 17 00:00:00 2001 From: MudassarTariq Date: Sat, 24 Oct 2026 22:13:40 +0500 Subject: [PATCH 2/2] test: add Linux CI and plugin sync integration coverage --- .github/workflows/ci.yml | 40 +++++++ README.md | 13 ++- resources/plugin/sync_test.go | 206 ++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 resources/plugin/sync_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d86b85e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + linux: + name: Linux / Go ${{ matrix.go }} + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + go: ['1.26.10', '1.27.3'] + env: + GOTOOLCHAIN: local + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 + with: + go-version: ${{ matrix.go }} + - name: Verify modules + run: go mod verify + - name: Test with race detection + run: go test -race -count=1 -timeout=5m ./... + - name: Test legacy HTTP/2 transport with race detection + run: go test -race -tags=http2legacy -count=1 -timeout=5m ./... + - name: Vet + run: go vet ./... + - name: Build Linux binary + run: CGO_ENABLED=0 go build -o "$RUNNER_TEMP/cq-source-ipgeolocation" ./ + - name: Check for reachable vulnerabilities + run: | + go install golang.org/x/vuln/cmd/govulncheck@v1.9.0 + govulncheck ./... diff --git a/README.md b/README.md index a648be8..04d64fb 100644 --- a/README.md +++ b/README.md @@ -122,12 +122,19 @@ The `example/` directory has eight configs you can run as is. ## Development ```bash -go build ./... # compile -go test ./... -v # unit tests, no API key needed +go build ./... +go test -race -count=1 ./... +go test -race -tags=http2legacy -count=1 ./... go vet ./... ``` -The tests use a stub HTTP server, so they run offline and make no API calls. +Tests use local HTTP servers and need no API key. The plugin sync integration test +runs all five tables through configuration, scheduling and Arrow row emission, +including optional modules, table filtering and caller-IP lookup. The legacy +transport run also exercises the x/net HTTP/2 implementation on Go 1.27. + +Linux CI runs both test modes, module verification, vet, a build and govulncheck +on Go 1.26.10 and 1.27.3. ## License diff --git a/resources/plugin/sync_test.go b/resources/plugin/sync_test.go new file mode 100644 index 0000000..1b8dad1 --- /dev/null +++ b/resources/plugin/sync_test.go @@ -0,0 +1,206 @@ +package plugin_test + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "sync" + "testing" + "time" + + "github.com/IPGeolocation/cq-source-ipgeolocation/client" + source "github.com/IPGeolocation/cq-source-ipgeolocation/resources/plugin" + "github.com/cloudquery/plugin-sdk/v4/message" + "github.com/cloudquery/plugin-sdk/v4/plugin" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestPluginSync(t *testing.T) { + const ip = "8.8.8.8" + const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0" + + for _, tc := range []struct { + name string + optional bool + filteredSelf bool + }{ + {name: "all_tables_default_modules"}, + {name: "all_tables_optional_modules", optional: true}, + {name: "filtered_table_and_caller_ip", filteredSelf: true}, + } { + t.Run(tc.name, func(t *testing.T) { + // Response shapes follow the official v3 documentation, as in the resolver tests. + security := map[string]any{"threat_score": 75, "is_proxy": true, "proxy_provider_names": []string{"Example Proxy", "Other Proxy"}} + abuse := map[string]any{"emails": []string{"abuse@example.com", "security@example.com"}, "phone_numbers": []string{"+1-555-0100"}} + geo := map[string]any{ + "ip": ip, "location": map[string]any{"country_code2": "US", "city": "Mountain View", "is_eu": false}, + "country_metadata": map[string]any{"languages": []string{"en-US", "es-US"}}, + "asn": map[string]any{"as_number": "AS15169", "organization": "Google LLC"}, + "time_zone": map[string]any{"name": "America/Los_Angeles", "offset": -8.0}, + } + asn := map[string]any{"as_number": "AS15169", "organization": "Google LLC"} + geoInclude, asnInclude := "", "" + geoRow := map[string]any{ + "ip": ip, "city": "Mountain View", "country_code2": "US", "is_eu": false, + "languages": "en-US,es-US", "asn_organization": "Google LLC", "timezone_offset": -8.0, + "threat_score": nil, "abuse_emails": nil, "hostname": nil, "accuracy_radius": nil, "dma_code": nil, + } + var routes, peers any + if tc.optional { + geoInclude = "security,abuse,geo_accuracy,dma_code,hostnameFallbackLive" + asnInclude = "peers,routes" + geo["security"], geo["abuse"], geo["hostname"] = security, abuse, "dns.google" + location := geo["location"].(map[string]any) + location["accuracy_radius"], location["dma_code"] = "5.0", "807" + asn["routes"] = []string{"8.8.8.0/24", "8.8.4.0/24"} + asn["peers"] = []map[string]string{{"as_number": "AS3356"}, {"as_number": "AS1299"}} + routes, peers = "8.8.8.0/24,8.8.4.0/24", "AS3356,AS1299" + geoRow["threat_score"], geoRow["abuse_emails"], geoRow["hostname"] = int64(75), "abuse@example.com,security@example.com", "dns.google" + geoRow["accuracy_radius"], geoRow["dma_code"] = "5.0", "807" + } + wantRows := map[string][]map[string]any{ + "ipgeolocation_ip_geolocation": {geoRow}, + "ipgeolocation_ip_security": {{ + "ip": ip, "threat_score": int64(75), "is_proxy": true, "proxy_provider_names": "Example Proxy,Other Proxy", + }}, + "ipgeolocation_abuse_contact": {{ + "ip": ip, "emails": "abuse@example.com,security@example.com", "phone_numbers": "+1-555-0100", + }}, + "ipgeolocation_asn": { + {"query_ip": ip, "query_asn": "", "as_number": "AS15169", "routes": routes, "peers": peers, "upstreams": nil}, + {"query_ip": "", "query_asn": "15169", "as_number": "AS15169", "routes": routes, "peers": peers, "upstreams": nil}, + }, + "ipgeolocation_user_agent": {{ + "user_agent_string": ua, "name": "Chrome", "device_name": "Windows Desktop", "os_name": "Windows", + }}, + } + wantCalls := map[string]int{"/v3/ipgeo": 1, "/v3/security": 1, "/v3/abuse": 1, "/v3/asn": 2, "/v3/user-agent": 1} + options := plugin.SyncOptions{Tables: []string{"ipgeolocation_*"}, DeterministicCQID: true} + if tc.filteredSelf { + for table := range wantRows { + if table != "ipgeolocation_ip_geolocation" { + options.SkipTables = append(options.SkipTables, table) + delete(wantRows, table) + } + } + wantCalls = map[string]int{"/v3/ipgeo": 1} + } + + var mu sync.Mutex + calls := make(map[string]int) + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + calls[r.URL.Path]++ + mu.Unlock() + assert.Equal(t, "test-api-key", r.URL.Query().Get("apiKey")) + assert.Equal(t, "cq-sync-test", r.Header.Get("User-Agent")) + assert.Equal(t, "application/json", r.Header.Get("Accept")) + w.Header().Set("Content-Type", "application/json") + var response any + if r.URL.Path == "/v3/user-agent" { + assert.Equal(t, http.MethodPost, r.Method) + assert.Equal(t, "application/json", r.Header.Get("Content-Type")) + var body map[string]string + assert.NoError(t, json.NewDecoder(r.Body).Decode(&body)) + assert.Equal(t, map[string]string{"uaString": ua}, body) + response = map[string]any{ + "user_agent_string": ua, "name": "Chrome", + "device": map[string]string{"name": "Windows Desktop"}, "operating_system": map[string]string{"name": "Windows"}, + } + } else { + assert.Equal(t, http.MethodGet, r.Method) + if r.URL.Path == "/v3/asn" && r.URL.Query().Has("asn") { + assert.Equal(t, "15169", r.URL.Query().Get("asn")) + assert.False(t, r.URL.Query().Has("ip")) + } else if tc.filteredSelf { + assert.False(t, r.URL.Query().Has("ip"), "caller-IP lookup must omit ip") + } else { + assert.Equal(t, ip, r.URL.Query().Get("ip")) + } + switch r.URL.Path { + case "/v3/ipgeo": + assert.Equal(t, geoInclude, r.URL.Query().Get("include")) + response = geo + case "/v3/security": + response = map[string]any{"ip": ip, "security": security} + case "/v3/abuse": + response = map[string]any{"ip": ip, "abuse": abuse} + case "/v3/asn": + assert.Equal(t, asnInclude, r.URL.Query().Get("include")) + response = map[string]any{"asn": asn} + default: + t.Errorf("unexpected API path: %s", r.URL.Path) + http.Error(w, "endpoint not defined", http.StatusNotImplemented) + return + } + } + assert.NoError(t, json.NewEncoder(w).Encode(response)) + })) + defer server.Close() + + spec := client.Spec{ + APIKey: "test-api-key", Endpoint: server.URL, UserAgent: "cq-sync-test", + Timeout: "2s", RetryAttempts: 1, Concurrency: 5, RateLimit: 1000, + IPs: []string{ip}, ASNs: []string{"15169"}, UserAgents: []string{ua}, + IncludeSecurity: tc.optional, IncludeAbuse: tc.optional, IncludeGeoAccuracy: tc.optional, + IncludeDMACode: tc.optional, IncludeHostname: tc.optional, + } + if tc.optional { + spec.ASNInclude = []string{"Routes", "PEERS", "peers"} + } + if tc.filteredSelf { + spec.IPs = nil + } + specBytes, err := json.Marshal(spec) + require.NoError(t, err) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + p := source.Plugin() + require.NoError(t, p.Init(ctx, specBytes, plugin.NewClientOptions{})) + defer func() { assert.NoError(t, p.Close(context.Background())) }() + messages, err := p.SyncAll(ctx, options) + for _, insert := range messages.GetInserts() { + defer insert.Record.Release() + } + require.NoError(t, err) + + var migrated []string + gotRows := make(map[string][]map[string]any) + for _, msg := range messages { + switch m := msg.(type) { + case *message.SyncMigrateTable: + migrated = append(migrated, m.Table.Name) + case *message.SyncInsert: + table := m.GetTable().Name + require.Contains(t, wantRows, table) + for row := 0; row < int(m.Record.NumRows()); row++ { + values := make(map[string]any) + for col, field := range m.Record.Schema().Fields() { + values[field.Name] = m.Record.Column(col).GetOneForMarshal(row) + } + assert.NotEmpty(t, values["_cq_id"], "table %s must emit a CloudQuery ID", table) + selected := make(map[string]any) + for column := range wantRows[table][0] { + require.Contains(t, values, column, "table %s", table) + selected[column] = values[column] + } + gotRows[table] = append(gotRows[table], selected) + } + default: + t.Fatalf("unexpected sync message: %#v", msg) + } + } + var wantTables []string + for table, rows := range wantRows { + wantTables = append(wantTables, table) + assert.ElementsMatch(t, rows, gotRows[table], "table %s", table) + } + assert.ElementsMatch(t, wantTables, migrated) + mu.Lock() + assert.Equal(t, wantCalls, calls, "sync must call only the selected endpoints") + mu.Unlock() + }) + } +}