github.com/kamilchm/hopper@v0.1.1-0.20150901175627-9ee9e15dce47/search_test.go (about) 1 package main 2 3 import ( 4 . "github.com/smartystreets/goconvey/convey" 5 "testing" 6 ) 7 8 func TestSearch(t *testing.T) { 9 Convey("Given no hops", t, func() { 10 noHops := hops{} 11 12 Convey("When searching exact hop", func() { 13 _, err := noHops.searchHop("some-hop") 14 15 Convey("It should fail with NotFound error", func() { 16 So(err, ShouldEqual, ErrHopNotFound) 17 }) 18 }) 19 20 }) 21 22 Convey("Given hops: hop1, hop3, some", t, func() { 23 defPerms := permissions{} 24 theHops := hops{ 25 "hop1": []Hop{&Docker{"a", "hop1", defPerms}}, 26 "hop3": []Hop{&Docker{"a", "hop3", defPerms}}, 27 "some": []Hop{&Docker{"a", "some", defPerms}}, 28 } 29 30 Convey("When search for hop1", func() { 31 found, _ := theHops.searchHop("hop1") 32 33 Convey("It should return only hop1", func() { 34 So(found, ShouldResemble, &hops{ 35 "hop1": []Hop{&Docker{"a", "hop1", defPerms}}, 36 }) 37 }) 38 }) 39 40 Convey("When search for hop2", func() { 41 _, err := theHops.searchHop("hop2") 42 43 Convey("It should fail with NotFound error", func() { 44 So(err, ShouldEqual, ErrHopNotFound) 45 }) 46 }) 47 48 Convey("When search for hop*", func() { 49 found, _ := theHops.searchHop("hop*") 50 51 Convey("It should return hop1 and hop3", func() { 52 So(found, ShouldResemble, &hops{ 53 "hop1": []Hop{&Docker{"a", "hop1", defPerms}}, 54 "hop3": []Hop{&Docker{"a", "hop3", defPerms}}, 55 }) 56 }) 57 }) 58 59 Convey("When search for hop3*", func() { 60 found, _ := theHops.searchHop("hop3*") 61 62 Convey("It should return only hop3", func() { 63 So(found, ShouldResemble, &hops{ 64 "hop3": []Hop{&Docker{"a", "hop3", defPerms}}, 65 }) 66 }) 67 }) 68 69 Convey("When search for *", func() { 70 found, _ := theHops.searchHop("*") 71 72 Convey("It should return all hops", func() { 73 So(found, ShouldResemble, &hops{ 74 "hop1": []Hop{&Docker{"a", "hop1", defPerms}}, 75 "hop3": []Hop{&Docker{"a", "hop3", defPerms}}, 76 "some": []Hop{&Docker{"a", "some", defPerms}}, 77 }) 78 }) 79 }) 80 81 Convey("When search for *o*", func() { 82 found, _ := theHops.searchHop("*o*") 83 84 Convey("It should return hop1, hop3, some", func() { 85 So(found, ShouldResemble, &hops{ 86 "hop1": []Hop{&Docker{"a", "hop1", defPerms}}, 87 "hop3": []Hop{&Docker{"a", "hop3", defPerms}}, 88 "some": []Hop{&Docker{"a", "some", defPerms}}, 89 }) 90 }) 91 }) 92 93 Convey("When search for o*", func() { 94 _, err := theHops.searchHop("o*") 95 96 Convey("It should fail with NotFound error", func() { 97 So(err, ShouldEqual, ErrHopNotFound) 98 }) 99 }) 100 }) 101 }