github.com/XiaoMi/Gaea@v1.2.5/proxy/plan/plan_unshard_test.go (about)

     1  package plan
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/XiaoMi/Gaea/backend"
     7  )
     8  
     9  func TestUnshardPlan(t *testing.T) {
    10  	ns, err := preparePlanInfo()
    11  	if err != nil {
    12  		t.Fatalf("prepare namespace error: %v", err)
    13  	}
    14  	tests := []SQLTestcase{
    15  		{
    16  			db:  "db_mycat",
    17  			sql: `select * from tbl_unshard_a as a join db_mycat.tbl_unshard_b as b on a.id = b.id`,
    18  			sqls: map[string]map[string][]string{
    19  				backend.DefaultSlice: {
    20  					"db_mycat_0": {"SELECT * FROM `tbl_unshard_a` AS `a` JOIN `db_mycat_0`.`tbl_unshard_b` AS `b` ON `a`.`id`=`b`.`id`"},
    21  				},
    22  			},
    23  		},
    24  	}
    25  	for _, test := range tests {
    26  		t.Run(test.sql, getTestFunc(ns, test))
    27  	}
    28  }
    29  
    30  func TestUnshardPlanWithoutDB(t *testing.T) {
    31  	ns, err := preparePlanInfo()
    32  	if err != nil {
    33  		t.Fatalf("prepare namespace error: %v", err)
    34  	}
    35  	tests := []SQLTestcase{
    36  		{
    37  			db:  "db_mycat",
    38  			sql: `select * from tbl_unshard limit 10`,
    39  			sqls: map[string]map[string][]string{
    40  				backend.DefaultSlice: {
    41  					"db_mycat_0": {"SELECT * FROM `tbl_unshard` LIMIT 10"},
    42  				},
    43  			},
    44  		},
    45  	}
    46  	for _, test := range tests {
    47  		t.Run(test.sql, getTestFunc(ns, test))
    48  	}
    49  }