Repository: matrixorigin/matrixcube (go)

Issue:
Add matrixone_test build tag
When build with the matrixone_test tag, extra types and methods can be included into the build. They would be mostly used in tests. 

This allows us to provide extra exported methods and types just for our tests without any impact on our production build. 

Pull request:
Added a matrixone_test build tag
**What type of PR is this?**

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [ ] Documentation
- [x] Feature
- [ ] Test and CI
- [ ] Code Refactoring

**Which issue(s) this PR fixes:**

Fixes #497 

**What this PR does / why we need it:**

Not Available

**Special notes for your reviewer:**

Not Available

**Additional documentation (e.g. design docs, usage docs, etc.):**

Not Available


Patch:
diff --git a/Makefile b/Makefile
index ef61832..39f96b9 100644
--- a/Makefile
+++ b/Makefile
@@ -48,9 +48,10 @@ $(info Running selected tests $(TEST_TO_RUN))
 SELECTED_TESTS=-run $(TEST_TO_RUN)
 endif
 
+TEST_TAGS=-tags matrixone_test
 SHORT_ONLY=-short
 TEST_OPTIONS=test -timeout=1200s -count=1 -v $(RACE_FLAG) $(COVER_FLAG) $(SELECTED_TESTS)
-GOTEST=$(GO) $(TEST_OPTIONS) $(SHORT_ONLY)
+GOTEST=$(GO) $(TEST_OPTIONS) $(SHORT_ONLY) $(TEST_TAGS)
 
 ###############################################################################
 # tests
diff --git a/raftstore/store_extension.go b/raftstore/store_extension.go
new file mode 100644
index 0000000..bc4f80c
--- /dev/null
+++ b/raftstore/store_extension.go
@@ -0,0 +1,38 @@
+// Copyright 2021 MatrixOrigin.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//go:build matrixone_test
+// +build matrixone_test
+
+package raftstore
+
+import (
+	"github.com/matrixorigin/matrixcube/logdb"
+)
+
+// types and methods defined here are only used in tests.
+
+// LogDBGetter is the interface used for accessing the logdb instance.
+// Note that unexpected changes to the state of LogDB might corrupt the entire
+// MatrixOne cluster. This interface should only be used in tests.
+type LogDBGetter interface {
+	// GetLogDV returns the LogDB instance.
+	GetLogDB() logdb.LogDB
+}
+
+// this should only be accessed by tests
+// unexpected changes to the state of LogDB might corrupt the entire MatrixOne
+// cluster.
+func (s *store) GetLogDB() logdb.LogDB {
+	return s.logdb
+}


Test patch:
diff --git a/raftstore/store_test.go b/raftstore/store_test.go
index 0942a38..e531e85 100644
--- a/raftstore/store_test.go
+++ b/raftstore/store_test.go
@@ -301,3 +301,11 @@ func TestCacheAndRemoveDroppedVoteMsg(t *testing.T) {
 	assert.True(t, ok)
 	assert.Equal(t, meta.RaftMessage{Message: raftpb.Message{Type: raftpb.MsgPreVote}}, v)
 }
+
+func TestLogDBGetter(t *testing.T) {
+	// we just check whether this can compile
+	var s interface{}
+	s = &store{}
+	getter := s.(LogDBGetter)
+	assert.Nil(t, getter.GetLogDB())
+}