github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/io/xlang/debezium/debezium.go (about)

     1  // Licensed to the Apache Software Foundation (ASF) under one or more
     2  // contributor license agreements.  See the NOTICE file distributed with
     3  // this work for additional information regarding copyright ownership.
     4  // The ASF licenses this file to You under the Apache License, Version 2.0
     5  // (the "License"); you may not use this file except in compliance with
     6  // the License.  You may obtain a copy of the License at
     7  //
     8  //    http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  // Package debezium contains integration tests for cross-language Debezium IO
    17  // transforms.
    18  package debezium
    19  
    20  import (
    21  	"github.com/apache/beam/sdks/v2/go/pkg/beam"
    22  	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx"
    23  	"github.com/apache/beam/sdks/v2/go/pkg/beam/io/xlang/debeziumio"
    24  	"github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert"
    25  )
    26  
    27  // ReadPipeline creates a pipeline for debeziumio.Read PTransform and validates the result.
    28  func ReadPipeline(addr, username, password, dbname, host, port string, connectorClass debeziumio.DriverClassName, maxrecords int64, connectionProperties []string) *beam.Pipeline {
    29  	p, s := beam.NewPipelineWithRoot()
    30  	result := debeziumio.Read(s.Scope("Read from debezium"), username, password, host, port,
    31  		connectorClass, reflectx.String, debeziumio.MaxRecord(maxrecords),
    32  		debeziumio.ConnectionProperties(connectionProperties), debeziumio.ExpansionAddr(addr))
    33  	expectedJson := `{"metadata":{"connector":"postgresql","version":"1.3.1.Final","name":"dbserver1","database":"inventory","schema":"inventory","table":"customers"},"before":null,"after":{"fields":{"last_name":"Thomas","id":1001,"first_name":"Sally","email":"sally.thomas@acme.com"}}}`
    34  	expected := beam.Create(s, expectedJson)
    35  	passert.Equals(s, result, expected)
    36  	return p
    37  }