good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
upper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
open
upper
Commits
e4727eb3
Commit
e4727eb3
authored
Apr 12, 2014
by
Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Adding test for ql.
parent
0ba5f9d5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
db_test.go
+83
-14
83 additions, 14 deletions
db_test.go
with
83 additions
and
14 deletions
db_test.go
+
83
−
14
View file @
e4727eb3
...
@@ -11,10 +11,17 @@ import (
...
@@ -11,10 +11,17 @@ import (
_
"upper.io/db/mongo"
_
"upper.io/db/mongo"
_
"upper.io/db/mysql"
_
"upper.io/db/mysql"
_
"upper.io/db/postgresql"
_
"upper.io/db/postgresql"
_
"upper.io/db/ql"
_
"upper.io/db/sqlite"
_
"upper.io/db/sqlite"
)
)
var
wrappers
=
[]
string
{
`sqlite`
,
`mysql`
,
`postgresql`
,
`mongo`
}
var
wrappers
=
[]
string
{
`sqlite`
,
`mysql`
,
`postgresql`
,
`mongo`
,
`ql`
,
}
var
(
var
(
errDriverErr
=
errors
.
New
(
`Driver error`
)
errDriverErr
=
errors
.
New
(
`Driver error`
)
...
@@ -42,6 +49,9 @@ var settings = map[string]*db.Settings{
...
@@ -42,6 +49,9 @@ var settings = map[string]*db.Settings{
User
:
`upperio`
,
User
:
`upperio`
,
Password
:
`upperio`
,
Password
:
`upperio`
,
},
},
`ql`
:
&
db
.
Settings
{
Database
:
`file://upperio_test.ql`
,
},
}
}
var
setupFn
=
map
[
string
]
func
(
driver
interface
{})
error
{
var
setupFn
=
map
[
string
]
func
(
driver
interface
{})
error
{
...
@@ -150,6 +160,49 @@ var setupFn = map[string]func(driver interface{}) error{
...
@@ -150,6 +160,49 @@ var setupFn = map[string]func(driver interface{}) error{
}
}
return
errDriverErr
return
errDriverErr
},
},
`ql`
:
func
(
driver
interface
{})
error
{
if
sqld
,
ok
:=
driver
.
(
*
sql
.
DB
);
ok
==
true
{
var
err
error
var
tx
*
sql
.
Tx
if
tx
,
err
=
sqld
.
Begin
();
err
!=
nil
{
return
err
}
_
,
err
=
tx
.
Exec
(
`DROP TABLE IF EXISTS birthdays`
)
if
err
!=
nil
{
return
err
}
_
,
err
=
tx
.
Exec
(
`CREATE TABLE birthdays (
name string,
born time
)`
)
if
err
!=
nil
{
return
err
}
_
,
err
=
tx
.
Exec
(
`DROP TABLE IF EXISTS fibonacci`
)
if
err
!=
nil
{
return
err
}
_
,
err
=
tx
.
Exec
(
`CREATE TABLE fibonacci (
input int,
output int
)`
)
if
err
!=
nil
{
return
err
}
if
err
=
tx
.
Commit
();
err
!=
nil
{
return
err
}
return
nil
}
return
errDriverErr
},
}
}
type
Birthday
struct
{
type
Birthday
struct
{
...
@@ -237,6 +290,8 @@ func TestSimpleCRUD(t *testing.T) {
...
@@ -237,6 +290,8 @@ func TestSimpleCRUD(t *testing.T) {
t
.
Fatalf
(
`Test for wrapper %s failed: %s`
,
wrapper
,
err
.
Error
())
t
.
Fatalf
(
`Test for wrapper %s failed: %s`
,
wrapper
,
err
.
Error
())
}
}
defer
sess
.
Close
()
controlItem
=
Birthday
{
controlItem
=
Birthday
{
Name
:
"Hayao Miyazaki"
,
Name
:
"Hayao Miyazaki"
,
Born
:
time
.
Date
(
1941
,
time
.
January
,
5
,
0
,
0
,
0
,
0
,
time
.
Local
),
Born
:
time
.
Date
(
1941
,
time
.
January
,
5
,
0
,
0
,
0
,
0
,
time
.
Local
),
...
@@ -254,25 +309,37 @@ func TestSimpleCRUD(t *testing.T) {
...
@@ -254,25 +309,37 @@ func TestSimpleCRUD(t *testing.T) {
var
id
interface
{}
var
id
interface
{}
id
,
err
=
col
.
Append
(
controlItem
)
if
id
,
err
=
col
.
Append
(
controlItem
);
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
`Could not append item with wrapper %s: %s`
,
wrapper
,
err
.
Error
())
t
.
Fatalf
(
`Could not append item with wrapper %s: %s`
,
wrapper
,
err
.
Error
())
}
}
var
res
db
.
Result
var
res
db
.
Result
if
wrapper
==
`mongo`
{
switch
wrapper
{
case
`mongo`
:
res
=
col
.
Find
(
db
.
Cond
{
"_id"
:
id
})
res
=
col
.
Find
(
db
.
Cond
{
"_id"
:
id
})
}
else
{
case
`ql`
:
res
=
col
.
Find
(
db
.
Cond
{
"id()"
:
id
})
default
:
res
=
col
.
Find
(
db
.
Cond
{
"id"
:
id
})
res
=
col
.
Find
(
db
.
Cond
{
"id"
:
id
})
}
}
var
testItem
Birthday
var
total
uint64
total
,
err
=
res
.
Count
()
res
.
One
(
&
testItem
)
if
total
!=
1
{
t
.
Fatalf
(
"%s: Expecting one row."
,
wrapper
)
}
var
testItem
Birthday
err
=
res
.
One
(
&
testItem
)
if
err
!=
nil
{
t
.
Fatalf
(
"%s One(): %s"
,
wrapper
,
err
)
}
if
reflect
.
DeepEqual
(
testItem
,
controlItem
)
==
false
{
if
reflect
.
DeepEqual
(
testItem
,
controlItem
)
==
false
{
t
.
Errorf
(
"Struct is different with wrapper %s."
,
wrapper
)
t
.
Errorf
(
"%s: testItem: %v
\n
"
,
testItem
)
t
.
Errorf
(
"%s: controlItem: %v
\n
"
,
controlItem
)
t
.
Fatalf
(
"%s: Structs are different"
,
wrapper
)
}
}
controlItem
.
Name
=
`宮崎駿`
controlItem
.
Name
=
`宮崎駿`
...
@@ -285,7 +352,7 @@ func TestSimpleCRUD(t *testing.T) {
...
@@ -285,7 +352,7 @@ func TestSimpleCRUD(t *testing.T) {
res
.
One
(
&
testItem
)
res
.
One
(
&
testItem
)
if
reflect
.
DeepEqual
(
testItem
,
controlItem
)
==
false
{
if
reflect
.
DeepEqual
(
testItem
,
controlItem
)
==
false
{
t
.
Error
f
(
"Struct is different with wrapper %s."
,
wrapper
)
t
.
Fatal
f
(
"Struct is different with wrapper %s."
,
wrapper
)
}
}
err
=
res
.
Remove
()
err
=
res
.
Remove
()
...
@@ -294,7 +361,6 @@ func TestSimpleCRUD(t *testing.T) {
...
@@ -294,7 +361,6 @@ func TestSimpleCRUD(t *testing.T) {
t
.
Fatalf
(
`Could not update with wrapper %s: %s`
,
wrapper
,
err
.
Error
())
t
.
Fatalf
(
`Could not update with wrapper %s: %s`
,
wrapper
,
err
.
Error
())
}
}
var
total
uint64
total
,
err
=
res
.
Count
()
total
,
err
=
res
.
Count
()
if
total
!=
0
{
if
total
!=
0
{
...
@@ -328,6 +394,7 @@ func TestFinds(t *testing.T) {
...
@@ -328,6 +394,7 @@ func TestFinds(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
`Test for wrapper %s failed: %s`
,
wrapper
,
err
.
Error
())
t
.
Fatalf
(
`Test for wrapper %s failed: %s`
,
wrapper
,
err
.
Error
())
}
}
defer
sess
.
Close
()
var
col
db
.
Collection
var
col
db
.
Collection
col
,
err
=
sess
.
Collection
(
"fibonacci"
)
col
,
err
=
sess
.
Collection
(
"fibonacci"
)
...
@@ -399,10 +466,12 @@ func TestFinds(t *testing.T) {
...
@@ -399,10 +466,12 @@ func TestFinds(t *testing.T) {
t
.
Fatalf
(
`%s: %s`
,
wrapper
,
err
.
Error
())
t
.
Fatalf
(
`%s: %s`
,
wrapper
,
err
.
Error
())
}
}
total
,
err
=
res
.
Count
()
if
total
,
err
=
res
.
Count
();
err
!=
nil
{
t
.
Fatalf
(
`%s: %s`
,
wrapper
,
err
.
Error
())
}
if
total
!=
0
{
if
total
!=
0
{
t
.
Fatalf
(
`Unexpected count %
s
.`
,
wrapper
)
t
.
Fatalf
(
`
%s:
Unexpected count %
d
.`
,
wrapper
,
total
)
}
}
res
=
col
.
Find
()
res
=
col
.
Find
()
...
@@ -410,7 +479,7 @@ func TestFinds(t *testing.T) {
...
@@ -410,7 +479,7 @@ func TestFinds(t *testing.T) {
total
,
err
=
res
.
Count
()
total
,
err
=
res
.
Count
()
if
total
!=
6
{
if
total
!=
6
{
t
.
Fatalf
(
`Unexpected count %
s
.`
,
wrapper
)
t
.
Fatalf
(
`
%s:
Unexpected count %
d
.`
,
wrapper
,
total
)
}
}
var
items
[]
Fibonacci
var
items
[]
Fibonacci
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment