Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique check: pass in actual value, not string version #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ _testmain.go
*.test

.*
.wercker
16 changes: 16 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package aranGO

import (
"fmt"
"log"
"os"
)

// Configure to start testing
var (
TestCollection = "TestCollection"
Expand All @@ -13,6 +19,16 @@ var (
s *Session
)

func init() {
if wercker := os.Getenv("WERCKER"); wercker == "true" {
log.Printf("Found WERCKER env!")
arangoPort := os.Getenv("ARANGODB_PORT_8529_TCP_PORT")
arangoIP := os.Getenv("ARANGODB_PORT_8529_TCP_ADDR")
TestServer = fmt.Sprintf("http://%s:%s", arangoIP, arangoPort)
}
log.Printf("using TestServer at %s", TestServer)
}

// document to test
type DocTest struct {
Document // arango Document to save id, key, rev
Expand Down
8 changes: 4 additions & 4 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ func Unique(m interface{}, db *Database, update bool, err Error) {
c := db.Col(col)
jname := Tag(m, fname, "json")
if jname != "" {
uniq, _ = c.Unique(jname, field.String(), update, "")
uniq, _ = c.Unique(jname, field.Interface(), update, "")
} else {
uniq, _ = c.Unique(fname, field.String(), update, "")
uniq, _ = c.Unique(fname, field.Interface(), update, "")
}
}
if !uniq {
Expand All @@ -278,9 +278,9 @@ func unique(m reflect.Value, val map[string]string, db *Database, uniq *bool, up
// search by example
jname := Tag(m, fname, "json")
if jname != "" {
*uniq, _ = db.Col(col).Unique(jname, field.String(), update, "")
*uniq, _ = db.Col(col).Unique(jname, field.Interface(), update, "")
} else {
*uniq, _ = db.Col(col).Unique(fname, field.String(), update, "")
*uniq, _ = db.Col(col).Unique(fname, field.Interface(), update, "")
}
}
if !*uniq {
Expand Down
4 changes: 2 additions & 2 deletions simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aranGO

import (
"testing"

"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func TestSimple(t *testing.T) {

// Example
TestDoc = DocTest{} // Clean TestDoc variable
cur, err := c.Example(map[string]interface{}{"Text" : TestString}, 0, 10)
cur, err := c.Example(map[string]interface{}{"Text": TestString}, 0, 10)
assert.Equal(t, TestDoc.Error, false)
assert.Nil(t, err)
assert.NotNil(t, cur)
Expand All @@ -51,5 +52,4 @@ func TestSimple(t *testing.T) {
assert.Equal(t, TestString, TestDoc.Text)

// need to add new functions!

}
27 changes: 27 additions & 0 deletions wercker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
box: golang
services:
- id: arangodb
env:
ARANGO_NO_AUTH: 1
build:
steps:
- install-packages:
packages: netcat
- setup-go-workspace:
package-dir: github.com/diegogub/aranGO
- script:
name: go get
code: |
go get -t
- script:
name: go build
code: |
go build ./...
- script:
name: Wait for Arangodb connection if it is slow
code: |
while ! nc -nvz $ARANGODB_PORT_8529_TCP_ADDR $ARANGODB_PORT_8529_TCP_PORT ; do echo "."; sleep 2; done
- script:
name: go test
code: |
go test ./...