github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/version/creator_version_gate_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 version
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  func TestChangefeedStateFromAdminJob(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	testCases := []struct {
    26  		creatorVersion string
    27  		expected       bool
    28  	}{
    29  		{
    30  			creatorVersion: "",
    31  			expected:       true,
    32  		},
    33  		{
    34  			creatorVersion: "4.0.12",
    35  			expected:       true,
    36  		},
    37  		{
    38  			creatorVersion: "4.0.14",
    39  			expected:       true,
    40  		},
    41  		{
    42  			creatorVersion: "4.0.15",
    43  			expected:       true,
    44  		},
    45  		{
    46  			creatorVersion: "4.0.16",
    47  			expected:       false,
    48  		},
    49  		{
    50  			creatorVersion: "5.0.0",
    51  			expected:       true,
    52  		},
    53  		{
    54  			creatorVersion: "5.0.1",
    55  			expected:       true,
    56  		},
    57  		{
    58  			creatorVersion: "5.0.6",
    59  			expected:       false,
    60  		},
    61  		{
    62  			creatorVersion: "5.1.0",
    63  			expected:       false,
    64  		},
    65  		{
    66  			creatorVersion: "5.2.0",
    67  			expected:       false,
    68  		},
    69  		{
    70  			creatorVersion: "5.3.0",
    71  			expected:       false,
    72  		},
    73  	}
    74  
    75  	for _, tc := range testCases {
    76  		creatorVersionGate := CreatorVersionGate{version: tc.creatorVersion}
    77  		require.Equal(t, tc.expected, creatorVersionGate.ChangefeedStateFromAdminJob())
    78  	}
    79  }
    80  
    81  func TestChangefeedAcceptUnknownProtocols(t *testing.T) {
    82  	t.Parallel()
    83  
    84  	testCases := []struct {
    85  		creatorVersion string
    86  		expected       bool
    87  	}{
    88  		{
    89  			creatorVersion: "",
    90  			expected:       true,
    91  		},
    92  		{
    93  			creatorVersion: "4.0.12",
    94  			expected:       true,
    95  		},
    96  		{
    97  			creatorVersion: "4.0.14",
    98  			expected:       true,
    99  		},
   100  		{
   101  			creatorVersion: "4.0.15",
   102  			expected:       true,
   103  		},
   104  		{
   105  			creatorVersion: "5.0.0",
   106  			expected:       true,
   107  		},
   108  		{
   109  			creatorVersion: "5.0.1",
   110  			expected:       true,
   111  		},
   112  		{
   113  			creatorVersion: "5.1.0",
   114  			expected:       true,
   115  		},
   116  		{
   117  			creatorVersion: "5.2.0",
   118  			expected:       true,
   119  		},
   120  		{
   121  			creatorVersion: "5.3.0",
   122  			expected:       true,
   123  		},
   124  		{
   125  			creatorVersion: "5.4.0",
   126  			expected:       false,
   127  		},
   128  	}
   129  
   130  	for _, tc := range testCases {
   131  		creatorVersionGate := CreatorVersionGate{version: tc.creatorVersion}
   132  		require.Equal(t, tc.expected, creatorVersionGate.ChangefeedAcceptUnknownProtocols())
   133  	}
   134  }
   135  
   136  func TestChangefeedAcceptProtocolInMysqlSinURI(t *testing.T) {
   137  	t.Parallel()
   138  
   139  	testCases := []struct {
   140  		creatorVersion string
   141  		expected       bool
   142  	}{
   143  		{
   144  			creatorVersion: "",
   145  			expected:       true,
   146  		},
   147  		{
   148  			creatorVersion: "4.0.12",
   149  			expected:       true,
   150  		},
   151  		{
   152  			creatorVersion: "4.0.14",
   153  			expected:       true,
   154  		},
   155  		{
   156  			creatorVersion: "4.0.15",
   157  			expected:       true,
   158  		},
   159  		{
   160  			creatorVersion: "5.0.0",
   161  			expected:       true,
   162  		},
   163  		{
   164  			creatorVersion: "5.0.1",
   165  			expected:       true,
   166  		},
   167  		{
   168  			creatorVersion: "5.1.0",
   169  			expected:       true,
   170  		},
   171  		{
   172  			creatorVersion: "5.2.0-nightly",
   173  			expected:       true,
   174  		},
   175  		{
   176  			creatorVersion: "5.3.0",
   177  			expected:       true,
   178  		},
   179  		{
   180  			creatorVersion: "6.1.0",
   181  			expected:       true,
   182  		},
   183  		{
   184  			creatorVersion: "6.1.1",
   185  			expected:       false,
   186  		},
   187  		{
   188  			creatorVersion: "6.2.0",
   189  			expected:       false,
   190  		},
   191  	}
   192  
   193  	for _, tc := range testCases {
   194  		creatorVersionGate := CreatorVersionGate{version: tc.creatorVersion}
   195  		require.Equal(t, tc.expected, creatorVersionGate.ChangefeedAcceptProtocolInMysqlSinURI())
   196  	}
   197  }
   198  
   199  func TestChangefeedInheritSchedulerConfigFromV66(t *testing.T) {
   200  	t.Parallel()
   201  
   202  	testCases := []struct {
   203  		creatorVersion string
   204  		expected       bool
   205  	}{
   206  		{
   207  			creatorVersion: "",
   208  			expected:       false,
   209  		},
   210  		{
   211  			creatorVersion: "4.0.12",
   212  			expected:       false,
   213  		},
   214  		{
   215  			creatorVersion: "6.6.0-aplha",
   216  			expected:       true,
   217  		},
   218  		{
   219  			creatorVersion: "6.6.0",
   220  			expected:       true,
   221  		},
   222  		{
   223  			creatorVersion: "6.7.0",
   224  			expected:       false,
   225  		},
   226  	}
   227  
   228  	for _, tc := range testCases {
   229  		creatorVersionGate := CreatorVersionGate{version: tc.creatorVersion}
   230  		require.Equal(t, tc.expected, creatorVersionGate.ChangefeedInheritSchedulerConfigFromV66())
   231  	}
   232  }