MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / testPluginCustom

Function testPluginCustom

plugins/destination/s3/client/client_test.go:78–137  ·  view source on GitHub ↗
(t *testing.T, s *spec.Spec)

Source from the content-addressed store, hash-verified

76}
77
78func testPluginCustom(t *testing.T, s *spec.Spec) {
79 ctx := context.Background()
80
81 var client plugin.Client
82
83 p := plugin.NewPlugin("s3", "development", func(ctx context.Context, logger zerolog.Logger, spec []byte, opts plugin.NewClientOptions) (plugin.Client, error) {
84 var err error
85 client, err = New(ctx, logger, spec, opts)
86 return client, err
87 })
88 b, err := json.Marshal(s)
89 if err != nil {
90 t.Fatal(err)
91 }
92 if err := p.Init(ctx, b, plugin.NewClientOptions{}); err != nil {
93 t.Fatal(err)
94 }
95
96 tableName := fmt.Sprintf("cq_test_custom_insert_%d", time.Now().UnixNano())
97 table := &schema.Table{
98 Name: tableName,
99 Columns: []schema.Column{
100 {Name: "name", Type: arrow.BinaryTypes.String},
101 },
102 }
103 if err := p.WriteAll(ctx, []message.WriteMessage{
104 &message.WriteMigrateTable{
105 Table: table,
106 },
107 }); err != nil {
108 t.Fatal(fmt.Errorf("failed to create table: %w", err))
109 }
110
111 bldr := array.NewRecordBuilder(memory.DefaultAllocator, table.ToArrowSchema())
112 bldr.Field(0).(*array.StringBuilder).Append("foo")
113 record := bldr.NewRecordBatch()
114
115 if err := p.WriteAll(ctx, []message.WriteMessage{
116 &message.WriteInsert{
117 Record: record,
118 },
119 &message.WriteInsert{
120 Record: record,
121 },
122 }); err != nil {
123 t.Fatal(fmt.Errorf("failed to insert record: %w", err))
124 }
125
126 if err := client.Close(ctx); err != nil {
127 t.Fatal(fmt.Errorf("failed to close client: %w", err))
128 }
129
130 assert.EventuallyWithT(t, func(c *assert.CollectT) {
131 readRecords, err := readAll(ctx, client, table)
132 assert.NoError(c, err)
133
134 totalItems := plugin.TotalRows(readRecords)
135 assert.Equalf(c, int64(2), totalItems, "expected 2 items, got %d", totalItems)

Callers 1

TestPluginFunction · 0.70

Calls 5

CloseMethod · 0.95
ErrorfMethod · 0.80
AppendMethod · 0.80
NewFunction · 0.70
readAllFunction · 0.70

Tested by

no test coverage detected