github.com/matrixorigin/matrixone@v0.7.0/pkg/frontend/variables_test.go (about)

     1  // Copyright 2022 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 frontend
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    21  	"github.com/smartystreets/goconvey/convey"
    22  )
    23  
    24  func TestScope(t *testing.T) {
    25  	convey.Convey("test scope", t, func() {
    26  		wanted := make(map[Scope]string)
    27  		for i := ScopeGlobal; i <= ScopeResetPersist; i++ {
    28  			wanted[i] = i.String()
    29  		}
    30  
    31  		convey.So(wanted[ScopeBoth], convey.ShouldEqual, ScopeBoth.String())
    32  	})
    33  }
    34  
    35  func TestSystemVariable(t *testing.T) {
    36  	convey.Convey("all", t, func() {
    37  		bt := SystemVariableBoolType{}
    38  		it := SystemVariableIntType{}
    39  		ut := SystemVariableUintType{}
    40  		dt := SystemVariableDoubleType{}
    41  		et := SystemVariableEnumType{}
    42  		sett := SystemVariableSetType{}
    43  		st := SystemVariableStringType{}
    44  		nt := SystemVariableNullType{}
    45  		svs := []SystemVariableType{
    46  			bt,
    47  			it,
    48  			ut,
    49  			dt,
    50  			et,
    51  			sett,
    52  			st,
    53  			nt,
    54  		}
    55  
    56  		for _, sv := range svs {
    57  			fmt.Sprintln(sv.String(), sv.Type(), sv.MysqlType(), sv.Zero())
    58  		}
    59  
    60  		btrt, err := nt.Convert(nil)
    61  		convey.So(err, convey.ShouldBeNil)
    62  		convey.So(btrt, convey.ShouldBeNil)
    63  
    64  		_, err = nt.Convert("string")
    65  		convey.So(err, convey.ShouldNotBeNil)
    66  
    67  		_, err = bt.Convert(0)
    68  		convey.So(err, convey.ShouldBeNil)
    69  
    70  		_, err = bt.Convert(1)
    71  		convey.So(err, convey.ShouldBeNil)
    72  
    73  	})
    74  }