mirror of https://github.com/perkeep/perkeep.git
mysql indexer: start of tests.
Change-Id: I5df79f57607b5e4fe4f67f79a8e5ba8966e8dec5
This commit is contained in:
parent
2d0e0de553
commit
427ef88dc2
|
@ -58,7 +58,7 @@ func TestFiles_Memory(t *testing.T) {
|
|||
var (
|
||||
// those dirs are not packages implementing indexers,
|
||||
// hence we do not want to check them.
|
||||
excludedDirs = []string{"indextest", "testdata", "mysql"}
|
||||
excludedDirs = []string{"indextest", "testdata"}
|
||||
// A map is used in hasAllRequiredTests to note which required
|
||||
// tests have been found in a package, by setting the corresponding
|
||||
// booleans to true. Those are the keys for this map.
|
||||
|
@ -85,7 +85,7 @@ func hasAllRequiredTests(path string, t *testing.T) error {
|
|||
defer dir.Close()
|
||||
|
||||
for _, name := range names {
|
||||
if !strings.HasSuffix(name, "_test.go") {
|
||||
if strings.HasPrefix(name, ".") || !strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
|
@ -130,16 +130,19 @@ func TestIndexerTestsCompleteness(t *testing.T) {
|
|||
|
||||
for _, file := range files {
|
||||
name := file.Name()
|
||||
if !file.IsDir() || strings.HasPrefix(name, "_") || skipDir(name) {
|
||||
if !file.IsDir() || skipDir(name) {
|
||||
continue
|
||||
}
|
||||
if err := hasAllRequiredTests(name, t); err != nil {
|
||||
t.Fatalf("dir %q missing tests: %v", err)
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func skipDir(name string) bool {
|
||||
if strings.HasPrefix(name, "_") {
|
||||
return true
|
||||
}
|
||||
for _, v := range excludedDirs {
|
||||
if v == name {
|
||||
return true
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
Copyright 2012 Google Inc.
|
||||
|
||||
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,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package mysql_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"camlistore.org/pkg/index"
|
||||
"camlistore.org/pkg/index/indextest"
|
||||
_ "camlistore.org/pkg/index/mysql" // TODO: use
|
||||
|
||||
_ "camlistore.org/third_party/github.com/ziutek/mymysql/godrv"
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
dbAvailable bool
|
||||
rootdb *sql.DB
|
||||
)
|
||||
|
||||
func checkDB() {
|
||||
var err error
|
||||
if rootdb, err = sql.Open("mymysql", "mysql/root/root"); err == nil {
|
||||
dbAvailable = true
|
||||
return
|
||||
}
|
||||
if rootdb, err = sql.Open("mymysql", "mysql/root/"); err == nil {
|
||||
dbAvailable = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func makeIndex() *index.Index {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
type mysqlTester struct{}
|
||||
|
||||
func (mysqlTester) test(t *testing.T, tfn func(*testing.T, func() *index.Index)) {
|
||||
t.Logf("TODO: implement")
|
||||
return
|
||||
|
||||
once.Do(checkDB)
|
||||
if !dbAvailable {
|
||||
err := errors.New("Not running; start a MySQL daemon on the standard port (3306) with root password 'root' or '' (empty).")
|
||||
t.Fatalf("MySQL not available locally for testing: %v", err)
|
||||
}
|
||||
tfn(t, makeIndex)
|
||||
}
|
||||
|
||||
func TestIndex_MySQL(t *testing.T) {
|
||||
mysqlTester{}.test(t, indextest.Index)
|
||||
}
|
||||
|
||||
func TestPathsOfSignerTarget_MySQL(t *testing.T) {
|
||||
mysqlTester{}.test(t, indextest.PathsOfSignerTarget)
|
||||
}
|
||||
|
||||
func TestFiles_MysQL(t *testing.T) {
|
||||
mysqlTester{}.test(t, indextest.Files)
|
||||
}
|
Loading…
Reference in New Issue