github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/checker/mysql_server_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 checker
    15  
    16  import (
    17  	"context"
    18  	"testing"
    19  
    20  	"github.com/DATA-DOG/go-sqlmock"
    21  	"github.com/pingcap/tidb/pkg/util/dbutil"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestMysqlVersion(t *testing.T) {
    26  	versionChecker := &MySQLVersionChecker{}
    27  
    28  	cases := []struct {
    29  		rawVersion string
    30  		pass       bool
    31  	}{
    32  		{"5.5.0-log", false},
    33  		{"5.6.0-log", true},
    34  		{"5.7.0-log", true},
    35  		{"5.8.0-log", true}, // although it does not exist
    36  		{"8.0.1-log", true},
    37  		{"8.0.20", true},
    38  		{"8.0.35", true},
    39  		{"8.1.0", false},
    40  		{"5.5.50-MariaDB-1~wheezy", false},
    41  		{"10.1.1-MariaDB-1~wheezy", false},
    42  		{"10.1.2-MariaDB-1~wheezy", false},
    43  		{"10.13.1-MariaDB-1~wheezy", false},
    44  	}
    45  
    46  	for _, cs := range cases {
    47  		result := &Result{
    48  			State: StateWarning,
    49  		}
    50  		versionChecker.checkVersion(cs.rawVersion, result)
    51  		require.Equal(t, result.State == StateSuccess, cs.pass)
    52  	}
    53  }
    54  
    55  func TestVersionInstruction(t *testing.T) {
    56  	db, mock, err := sqlmock.New()
    57  	require.NoError(t, err)
    58  	versionChecker := &MySQLVersionChecker{
    59  		db:     db,
    60  		dbinfo: &dbutil.DBConfig{},
    61  	}
    62  	mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version';").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("version", "8.1.0"))
    63  	result := versionChecker.Check(context.Background())
    64  	require.Equal(t, result.State, StateWarning)
    65  	require.Equal(t, result.Instruction, "It is recommended that you select a database version that meets the requirements before performing data migration. Otherwise data inconsistency or task exceptions might occur.")
    66  }