vitess.io/vitess@v0.16.2/go/vt/vtgate/engine/update_target_test.go (about)

     1  /*
     2  Copyright 2020 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  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  
    17  package engine
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/require"
    24  
    25  	querypb "vitess.io/vitess/go/vt/proto/query"
    26  )
    27  
    28  func TestUpdateTargetTable(t *testing.T) {
    29  	type testCase struct {
    30  		targetString     string
    31  		expectedQueryLog []string
    32  	}
    33  
    34  	tests := []testCase{
    35  		{
    36  			targetString: "ks:-80@replica",
    37  			expectedQueryLog: []string{
    38  				`Target set to ks:-80@replica`,
    39  			},
    40  		},
    41  		{
    42  			targetString: "",
    43  			expectedQueryLog: []string{
    44  				`Target set to `,
    45  			},
    46  		},
    47  	}
    48  
    49  	for _, tc := range tests {
    50  		t.Run(tc.targetString, func(t *testing.T) {
    51  			updateTarget := &UpdateTarget{
    52  				Target: tc.targetString,
    53  			}
    54  			vc := &loggingVCursor{}
    55  			_, err := updateTarget.TryExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false)
    56  			require.NoError(t, err)
    57  			vc.ExpectLog(t, tc.expectedQueryLog)
    58  
    59  			vc = &loggingVCursor{}
    60  			_, err = wrapStreamExecute(updateTarget, vc, map[string]*querypb.BindVariable{}, false)
    61  			require.NoError(t, err)
    62  			vc.ExpectLog(t, tc.expectedQueryLog)
    63  		})
    64  	}
    65  }
    66  
    67  func TestUpdateTargetGetFields(t *testing.T) {
    68  	updateTarget := &UpdateTarget{}
    69  	vc := &noopVCursor{}
    70  	_, err := updateTarget.GetFields(context.Background(), vc, map[string]*querypb.BindVariable{})
    71  	require.EqualError(t, err, "[BUG] GetFields not reachable for use statement")
    72  }