github.com/jbking/gohan@v0.0.0-20151217002006-b41ccf1c2a96/server/server_suite_test.go (about) 1 // Copyright (C) 2015 NTT Innovation Institute, 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 // implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package server_test 17 18 import ( 19 "os" 20 "testing" 21 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 25 "github.com/cloudwan/gohan/db" 26 "github.com/cloudwan/gohan/schema" 27 ) 28 29 const ( 30 adminTokenID = "admin_token" 31 memberTokenID = "member_token" 32 powerUserTokenID = "power_user_token" 33 adminTenantID = "fc394f2ab2df4114bde39905f800dc57" 34 memberTenantID = "fc394f2ab2df4114bde39905f800dc57" 35 powerUserTenantID = "acf5662bbff44060b93ac3db3c25a590" 36 ) 37 38 var ( 39 testDB db.DB 40 whitelist = map[string]bool{ 41 "schema": true, 42 "policy": true, 43 "extension": true, 44 "namespace": true, 45 } 46 ) 47 48 func TestServer(t *testing.T) { 49 RegisterFailHandler(Fail) 50 RunSpecs(t, "Server Suite") 51 } 52 53 var _ = Describe("Suit set up and tear down", func() { 54 var conn, dbType string 55 if os.Getenv("MYSQL_TEST") == "true" { 56 conn = "root@/gohan_test" 57 dbType = "mysql" 58 } else { 59 conn = "./test.db" 60 dbType = "sqlite3" 61 } 62 63 var _ = BeforeSuite(func() { 64 var err error 65 testDB, err = db.ConnectDB(dbType, conn) 66 Expect(err).ToNot(HaveOccurred(), "Failed to connect database.") 67 if os.Getenv("MYSQL_TEST") == "true" { 68 err = startTestServer("./server_test_mysql_config.yaml") 69 } else { 70 err = startTestServer("./server_test_config.yaml") 71 } 72 Expect(err).ToNot(HaveOccurred(), "Failed to start test server.") 73 }) 74 75 var _ = AfterSuite(func() { 76 schema.ClearManager() 77 os.Remove(conn) 78 }) 79 })