vitess.io/vitess@v0.16.2/go/mysql/flavor_test.go (about)

     1  /*
     2  Copyright 2022 The Vitess Authors.
     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      http://www.apache.org/licenses/LICENSE-2.0
     7  Unless required by applicable law or agreed to in writing, software
     8  distributed under the License is distributed on an "AS IS" BASIS,
     9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  See the License for the specific language governing permissions and
    11  limitations under the License.
    12  */
    13  
    14  package mysql
    15  
    16  import (
    17  	"fmt"
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  func TestServerVersionAtLeast(t *testing.T) {
    24  	testcases := []struct {
    25  		version     string
    26  		parts       []int
    27  		expect      bool
    28  		expectError bool
    29  	}{
    30  		{
    31  			version: "8.0.14",
    32  			parts:   []int{8, 0, 14},
    33  			expect:  true,
    34  		},
    35  		{
    36  			version: "8.0.14-log",
    37  			parts:   []int{8, 0, 14},
    38  			expect:  true,
    39  		},
    40  		{
    41  			version: "8.0.14",
    42  			parts:   []int{8, 0, 13},
    43  			expect:  true,
    44  		},
    45  		{
    46  			version: "8.0.14",
    47  			parts:   []int{7, 5, 20},
    48  			expect:  true,
    49  		},
    50  		{
    51  			version: "8.0.14",
    52  			parts:   []int{7, 5},
    53  			expect:  true,
    54  		},
    55  		{
    56  			version: "8.0.14-log",
    57  			parts:   []int{7, 5, 20},
    58  			expect:  true,
    59  		},
    60  		{
    61  			version: "8.0.14",
    62  			parts:   []int{8, 1, 2},
    63  			expect:  false,
    64  		},
    65  		{
    66  			version: "8.0.14",
    67  			parts:   []int{10, 1, 2},
    68  			expect:  false,
    69  		},
    70  		{
    71  			version: "8.0",
    72  			parts:   []int{8, 0, 14},
    73  			expect:  false,
    74  		},
    75  		{
    76  			version:     "8.0.x",
    77  			parts:       []int{8, 0, 14},
    78  			expectError: true,
    79  		},
    80  	}
    81  	for _, tc := range testcases {
    82  		result, err := ServerVersionAtLeast(tc.version, tc.parts...)
    83  		if tc.expectError {
    84  			assert.Error(t, err)
    85  		} else {
    86  			assert.NoError(t, err)
    87  			assert.Equal(t, tc.expect, result)
    88  		}
    89  	}
    90  }
    91  
    92  func TestGetFlavor(t *testing.T) {
    93  	testcases := []struct {
    94  		version    string
    95  		capability FlavorCapability
    96  		isCapable  bool
    97  	}{
    98  		{
    99  			version:    "8.0.14",
   100  			capability: InstantDDLFlavorCapability,
   101  			isCapable:  true,
   102  		},
   103  		{
   104  			version:    "8.0.20",
   105  			capability: TransactionalGtidExecutedFlavorCapability,
   106  			isCapable:  true,
   107  		},
   108  		{
   109  			version:    "8.0.0",
   110  			capability: InstantAddLastColumnFlavorCapability,
   111  			isCapable:  true,
   112  		},
   113  		{
   114  			version:    "8.0.0",
   115  			capability: InstantAddDropColumnFlavorCapability,
   116  			isCapable:  false,
   117  		},
   118  		{
   119  			version:    "5.6.7",
   120  			capability: InstantDDLFlavorCapability,
   121  			isCapable:  false,
   122  		},
   123  		{
   124  			version:    "5.7.29",
   125  			capability: TransactionalGtidExecutedFlavorCapability,
   126  			isCapable:  false,
   127  		},
   128  		{
   129  			version:    "5.6.7",
   130  			capability: MySQLJSONFlavorCapability,
   131  			isCapable:  false,
   132  		},
   133  		{
   134  			version:    "5.7.29",
   135  			capability: MySQLJSONFlavorCapability,
   136  			isCapable:  true,
   137  		},
   138  		{
   139  			version:    "8.0.30",
   140  			capability: DynamicRedoLogCapacityFlavorCapability,
   141  			isCapable:  true,
   142  		},
   143  		{
   144  			version:    "8.0.29",
   145  			capability: DynamicRedoLogCapacityFlavorCapability,
   146  			isCapable:  false,
   147  		},
   148  		{
   149  			version:    "5.7.38",
   150  			capability: DynamicRedoLogCapacityFlavorCapability,
   151  			isCapable:  false,
   152  		},
   153  		{
   154  			version:    "8.0.21",
   155  			capability: DisableRedoLogFlavorCapability,
   156  			isCapable:  true,
   157  		},
   158  		{
   159  			version:    "8.0.20",
   160  			capability: DisableRedoLogFlavorCapability,
   161  			isCapable:  false,
   162  		},
   163  	}
   164  	for _, tc := range testcases {
   165  		name := fmt.Sprintf("%s %v", tc.version, tc.capability)
   166  		t.Run(name, func(t *testing.T) {
   167  			_, capableOf, _ := GetFlavor(tc.version, nil)
   168  			isCapable, err := capableOf(tc.capability)
   169  			assert.NoError(t, err)
   170  			assert.Equal(t, tc.isCapable, isCapable)
   171  		})
   172  	}
   173  }