From 427ef88dc2707a5ff8370283c28bc87245f3a0dd Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 28 Mar 2012 17:15:37 -0700 Subject: [PATCH] mysql indexer: start of tests. Change-Id: I5df79f57607b5e4fe4f67f79a8e5ba8966e8dec5 --- pkg/index/index_test.go | 11 +++-- pkg/index/mysql/mysql_test.go | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 pkg/index/mysql/mysql_test.go diff --git a/pkg/index/index_test.go b/pkg/index/index_test.go index fbc068d1f..3fc8623ec 100644 --- a/pkg/index/index_test.go +++ b/pkg/index/index_test.go @@ -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 diff --git a/pkg/index/mysql/mysql_test.go b/pkg/index/mysql/mysql_test.go new file mode 100644 index 000000000..fa102b01d --- /dev/null +++ b/pkg/index/mysql/mysql_test.go @@ -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) +}