github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/compile/sql_executor_context_test.go (about)

     1  // Copyright 2023 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package compile
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/golang/mock/gomock"
    21  	"github.com/stretchr/testify/require"
    22  
    23  	mock_frontend "github.com/matrixorigin/matrixone/pkg/frontend/test"
    24  	"github.com/matrixorigin/matrixone/pkg/sql/plan"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    26  )
    27  
    28  func Test_panic(t *testing.T) {
    29  	r := func() {
    30  		err := recover()
    31  		require.Equal(t, "not supported in internal sql executor", err)
    32  	}
    33  
    34  	c := &compilerContext{}
    35  
    36  	func() {
    37  		defer r()
    38  		_ = c.CheckSubscriptionValid("", "", "")
    39  	}()
    40  
    41  	func() {
    42  		defer r()
    43  		_, _ = c.IsPublishing("")
    44  	}()
    45  
    46  	func() {
    47  		defer r()
    48  		c.SetQueryingSubscription(nil)
    49  	}()
    50  
    51  	func() {
    52  		defer r()
    53  		_, _ = c.ResolveUdf("", nil)
    54  	}()
    55  
    56  	func() {
    57  		defer r()
    58  		_, _ = c.ResolveAccountIds(nil)
    59  	}()
    60  
    61  	func() {
    62  		defer r()
    63  		_, _, _ = c.GetQueryResultMeta("")
    64  	}()
    65  }
    66  
    67  func TestCompilerContext_Database(t *testing.T) {
    68  	ctrl := gomock.NewController(t)
    69  	database := mock_frontend.NewMockDatabase(ctrl)
    70  	database.EXPECT().GetDatabaseId(nil).Return("1")
    71  	engine := mock_frontend.NewMockEngine(ctrl)
    72  	engine.EXPECT().Database(nil, "", nil).Return(database, nil).Times(2)
    73  
    74  	c := &compilerContext{
    75  		proc:   &process.Process{},
    76  		engine: engine,
    77  	}
    78  
    79  	exists := c.DatabaseExists("", plan.Snapshot{})
    80  	require.Equal(t, exists, true)
    81  
    82  	_, err := c.GetDatabaseId("", plan.Snapshot{})
    83  	require.Nil(t, err)
    84  
    85  	sql := c.GetRootSql()
    86  	require.Equal(t, sql, "")
    87  }