Skip to content

Instantly share code, notes, and snippets.

@mrkaspa
Created August 27, 2016 16:00
Show Gist options
  • Save mrkaspa/681fb1e65762993452ee8a4f827c998d to your computer and use it in GitHub Desktop.
Save mrkaspa/681fb1e65762993452ee8a4f827c998d to your computer and use it in GitHub Desktop.
package models
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gopkg.in/mgo.v2/bson"
)
var _ = Describe("persistor", func() {
a1 := Stroke{
UserID: "a1",
Info: "a1",
Location: []float64{-79.38066843, 43.65483486},
}
a2 := Stroke{
UserID: "a2",
Info: "a2",
Location: []float64{-79.38066843, 43.65483486},
}
a3 := Stroke{
UserID: "a2",
Info: "a2",
Location: []float64{59.38066843, 43.65483486},
}
strokesTests := []struct {
stroke Stroke
strokeNear StrokeNear
expectedResults int
}{
{a1, StrokeNear{5, 10, a2}, 1},
{a1, StrokeNear{5, 10, a1}, 0},
{a1, StrokeNear{5, 10, a3}, 0},
}
cleanDB := func() {
StrokesCollection.RemoveAll(bson.M{})
}
BeforeEach(func() {
cleanDB()
})
It("should save the stroke", func() {
persistor := NewPersistor()
err := persistor.Persist(Stroke{
UserID: "a1",
Info: "a1",
Location: []float64{-79.38066843, 43.65483486},
})
Expect(err).To(BeNil())
strokes, err := persistor.FindStrokes("a1")
Expect(err).To(BeNil())
Expect(strokes).ToNot(BeEmpty())
})
for i, tt := range strokesTests {
It("should get the expected matches", func() {
persistor := NewPersistor()
fmt.Printf("running %d", i)
err := persistor.Persist(tt.stroke)
Expect(err).To(BeNil())
strokes, err := persistor.PersistAndFind(tt.strokeNear)
Expect(err).To(BeNil())
Expect(len(strokes)).To(Equal(tt.expectedResults))
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment