vitess.io/vitess@v0.16.2/go/test/fuzzing/tablet_manager_fuzzer.go (about)

     1  /*
     2  Copyright 2021 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 fuzzing
    15  
    16  import (
    17  	"context"
    18  	"sync"
    19  	"testing"
    20  
    21  	"vitess.io/vitess/go/mysql"
    22  	"vitess.io/vitess/go/mysql/fakesqldb"
    23  	"vitess.io/vitess/go/sqltypes"
    24  	"vitess.io/vitess/go/vt/dbconfigs"
    25  	"vitess.io/vitess/go/vt/mysqlctl/fakemysqldaemon"
    26  	"vitess.io/vitess/go/vt/vttablet/tabletmanager"
    27  	"vitess.io/vitess/go/vt/vttablet/tabletservermock"
    28  
    29  	tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
    30  )
    31  
    32  var fuzzInitter sync.Once
    33  
    34  func initTesting() {
    35  	testing.Init()
    36  }
    37  
    38  func FuzzTabletManagerExecuteFetchAsDba(data []byte) int {
    39  	fuzzInitter.Do(initTesting)
    40  	t := &testing.T{}
    41  	ctx := context.Background()
    42  	cp := mysql.ConnParams{}
    43  	db := fakesqldb.New(t)
    44  	db.AddQueryPattern(".*", &sqltypes.Result{})
    45  	daemon := fakemysqldaemon.NewFakeMysqlDaemon(db)
    46  
    47  	dbName := "dbname"
    48  	tm := &tabletmanager.TabletManager{
    49  		MysqlDaemon:         daemon,
    50  		DBConfigs:           dbconfigs.NewTestDBConfigs(cp, cp, dbName),
    51  		QueryServiceControl: tabletservermock.NewController(),
    52  	}
    53  	_, _ = tm.ExecuteFetchAsDba(ctx, &tabletmanagerdatapb.ExecuteFetchAsDbaRequest{
    54  		Query:   data,
    55  		DbName:  dbName,
    56  		MaxRows: 10,
    57  	})
    58  	return 1
    59  }