github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/stochastikctx/variable/statusvar_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package variable 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/milevadb/soliton/testleak" 19 ) 20 21 var _ = Suite(&testStatusVarSuite{}) 22 23 type testStatusVarSuite struct { 24 ms *mockStatistics 25 } 26 27 func (s *testStatusVarSuite) SetUpSuite(c *C) { 28 s.ms = &mockStatistics{} 29 RegisterStatistics(s.ms) 30 } 31 32 // mockStatistics represents mocked statistics. 33 type mockStatistics struct{} 34 35 const ( 36 testStatus = "test_status" 37 testStochastikStatus = "test_stochastik_status" 38 testStatusVal = "test_status_val" 39 ) 40 41 var specificStatusScopes = map[string]ScopeFlag{ 42 testStochastikStatus: ScopeStochastik, 43 } 44 45 func (ms *mockStatistics) GetScope(status string) ScopeFlag { 46 scope, ok := specificStatusScopes[status] 47 if !ok { 48 return DefaultStatusVarScopeFlag 49 } 50 51 return scope 52 } 53 54 func (ms *mockStatistics) Stats(vars *StochastikVars) (map[string]interface{}, error) { 55 m := make(map[string]interface{}, len(specificStatusScopes)) 56 m[testStatus] = testStatusVal 57 58 return m, nil 59 } 60 61 func (s *testStatusVarSuite) TestStatusVar(c *C) { 62 defer testleak.AfterTest(c)() 63 scope := s.ms.GetScope(testStatus) 64 c.Assert(scope, Equals, DefaultStatusVarScopeFlag) 65 scope = s.ms.GetScope(testStochastikStatus) 66 c.Assert(scope, Equals, ScopeStochastik) 67 68 vars, err := GetStatusVars(nil) 69 c.Assert(err, IsNil) 70 v := &StatusVal{Scope: DefaultStatusVarScopeFlag, Value: testStatusVal} 71 c.Assert(v, DeepEquals, vars[testStatus]) 72 }