-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lock-resource-before-delete
- Loading branch information
Showing
21 changed files
with
1,125 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (C) 2015 NTT Innovation Institute, 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 sql_test | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/cloudwan/gohan/db" | ||
. "github.com/cloudwan/gohan/db/sql" | ||
"github.com/cloudwan/gohan/schema" | ||
|
||
"context" | ||
|
||
"fmt" | ||
"strings" | ||
|
||
"github.com/cloudwan/gohan/db/transaction" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Mysql", func() { | ||
|
||
var ( | ||
conn string | ||
sqlConn *DB | ||
s *schema.Schema | ||
) | ||
|
||
BeforeEach(func() { | ||
if os.Getenv("MYSQL_TEST") != "true" { | ||
Skip("Test possible only on MySQL DB") | ||
} | ||
conn = "gohan:gohan@/gohan_test" | ||
dbType := "mysql" | ||
|
||
manager := schema.GetManager() | ||
dbc, err := db.ConnectDB(dbType, conn, db.DefaultMaxOpenConn) | ||
sqlConn = dbc.(*DB) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(manager.LoadSchemasFromFiles( | ||
"../../etc/schema/gohan.json", "../../tests/test_abstract_schema.yaml", "../../tests/test_schema.yaml")).To(Succeed()) | ||
db.InitDBWithSchemas(dbType, conn, true, false, false) | ||
|
||
var ok bool | ||
s, ok = manager.Schema("test") | ||
Expect(ok).To(BeTrue()) | ||
}) | ||
|
||
AfterEach(func() { | ||
sqlConn.Close() | ||
schema.ClearManager() | ||
}) | ||
|
||
Describe("Isolation levels", func() { | ||
|
||
It("Isolation level is set on transaction", func() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
tx1, err := sqlConn.BeginTx(ctx, &transaction.TxOptions{IsolationLevel: transaction.RepeatableRead}) | ||
Expect(err).To(Succeed()) | ||
|
||
tx2, err := sqlConn.BeginTx(ctx, &transaction.TxOptions{IsolationLevel: transaction.ReadCommited}) | ||
Expect(err).To(Succeed()) | ||
|
||
Expect(tx1.Exec("INSERT INTO `tests` (`id`, `tenant_id`) values ('id', 'tenant')")).To(Succeed()) | ||
|
||
selectQuery := fmt.Sprintf( | ||
"SELECT %s FROM %s", | ||
strings.Join(MakeColumns(s, s.GetDbTableName(), nil, false), ", "), | ||
s.GetDbTableName(), | ||
) | ||
results, err := tx2.Query(s, selectQuery, []interface{}{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(len(results)).To(Equal(0)) | ||
|
||
Expect(tx1.Commit()).To(Succeed()) | ||
|
||
results, err = tx2.Query(s, selectQuery, []interface{}{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(len(results)).To(Equal(1)) | ||
|
||
Expect(tx2.Commit()).To(Succeed()) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
vendor/github.com/go-sql-driver/mysql/ISSUE_TEMPLATE.md
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
vendor/github.com/go-sql-driver/mysql/PULL_REQUEST_TEMPLATE.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.