github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/config/source_converter_test.go (about)

     1  // Copyright 2021 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package config
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/pingcap/check"
    20  	"github.com/pingcap/tiflow/dm/openapi/fixtures"
    21  )
    22  
    23  func TestConfig(t *testing.T) {
    24  	check.TestingT(t)
    25  }
    26  
    27  type testConfig struct{}
    28  
    29  var _ = check.Suite(&testConfig{})
    30  
    31  func (t *testConfig) TestConverterWithSourceAndOpenAPISource(c *check.C) {
    32  	sourceCfg1, err := SourceCfgFromYaml(SampleSourceConfig)
    33  	c.Assert(err, check.IsNil)
    34  
    35  	// 1. test user create source from dmctl, after convert to openapi.Source then convert back to source config
    36  	sourceCfg2 := OpenAPISourceToSourceCfg(SourceCfgToOpenAPISource(sourceCfg1))
    37  
    38  	// we need set ServerID and MaxAllowedPacket manually, because user don't need to config those field in openapi
    39  	sourceCfg2.ServerID = sourceCfg1.ServerID
    40  	sourceCfg2.From.MaxAllowedPacket = sourceCfg1.From.MaxAllowedPacket
    41  
    42  	// we only need to make sure the source config that user can see is the same as the source config that user create
    43  	c.Assert(sourceCfg1.String(), check.Equals, sourceCfg2.String())
    44  
    45  	// 2. test user create source from openapi, after convert to source config then convert back to openapi.Source
    46  	openapiSource1, err := fixtures.GenOpenAPISourceForTest()
    47  	c.Assert(err, check.IsNil)
    48  	openapiSource2 := SourceCfgToOpenAPISource(OpenAPISourceToSourceCfg(openapiSource1))
    49  	openapiSource2.Password = openapiSource1.Password // we set passwd to "******" for privacy
    50  	c.Assert(openapiSource1, check.DeepEquals, openapiSource2)
    51  }