diff options
Diffstat (limited to 'example')
| -rw-r--r-- | example/Makefile | 3 | ||||
| -rw-r--r-- | example/fruit.New.go | 1 | ||||
| -rw-r--r-- | example/main.go | 41 |
3 files changed, 40 insertions, 5 deletions
diff --git a/example/Makefile b/example/Makefile index c744d23..6aaad50 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,6 +1,9 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d_%H%M) +test: goimports build + ./example + modproto: clean withMutex goimports vet build ./example diff --git a/example/fruit.New.go b/example/fruit.New.go index 6d32ded..0be9b07 100644 --- a/example/fruit.New.go +++ b/example/fruit.New.go @@ -4,5 +4,6 @@ func NewFruits() *Fruits { x := new(Fruits) x.Uuid = "test" x.Version = "v0.0.2" + // x.Fruits = return x } diff --git a/example/main.go b/example/main.go index 6222701..90efe25 100644 --- a/example/main.go +++ b/example/main.go @@ -20,22 +20,53 @@ var uniqueKeys []string var pb *Fruits func main() { - pb = NewFruits() + // pb = NewFruits() + pb = new(Fruits) + pb.Uuid = "test" + pb.Version = "v0.0.2" fruit := &Fruit{ Brand: "mom", City: "New NewYork", } + x := new(Fruit) + x = &Fruit{ + Brand: "dad", + City: "Germany", + } + appendByUPC(x) + appendByUPC(fruit) + + testAppend(fruit) + testAppend(x) +} + +func testAppend(fruit *Fruit) { if pb.AppendUnique(fruit) { - log.Info("AppendUnique() ok") + log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City) } else { - log.Info("AppendUnique() failed") + log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City) os.Exit(-1) } if pb.AppendUnique(fruit) { - log.Info("AppendUnique() worked but should not have") + log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City) + os.Exit(-1) + } else { + log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City) + } +} + +func appendByUPC(fruit *Fruit) { + if pb.AppendUniqueUPC(fruit) { + log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City) + } else { + log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City) + os.Exit(-1) + } + if pb.AppendUniqueUPC(fruit) { + log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City) os.Exit(-1) } else { - log.Info("AppendUnique() failed ok") + log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City) } } |
