From c3dcb649c776ca1b215d0ddc5417bc67f8f73cb0 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 5 Aug 2016 14:11:36 +0700 Subject: [PATCH] return bool if stream exists in StreamsMap GetStream --- streams_map.go | 6 +++--- streams_map_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/streams_map.go b/streams_map.go index da36dbc1..5c26cff0 100644 --- a/streams_map.go +++ b/streams_map.go @@ -19,14 +19,14 @@ func newStreamsMap() *streamsMap { } } -func (m *streamsMap) GetStream(id protocol.StreamID) (*stream, error) { +func (m *streamsMap) GetStream(id protocol.StreamID) (*stream, bool) { m.mutex.RLock() s, ok := m.streams[id] m.mutex.RUnlock() if !ok { - return nil, fmt.Errorf("unknown stream: %d", id) + return nil, false } - return s, nil + return s, true } func (m *streamsMap) PutStream(s *stream) error { diff --git a/streams_map_test.go b/streams_map_test.go index 725a092c..01ff9302 100644 --- a/streams_map_test.go +++ b/streams_map_test.go @@ -16,8 +16,8 @@ var _ = Describe("Streams Map", func() { }) It("returns an error for non-existant streams", func() { - _, err := m.GetStream(1) - Expect(err).To(MatchError("unknown stream: 1")) + _, exists := m.GetStream(1) + Expect(exists).To(BeFalse()) }) It("returns nil for previously existing streams", func() { @@ -25,8 +25,8 @@ var _ = Describe("Streams Map", func() { Expect(err).NotTo(HaveOccurred()) err = m.RemoveStream(1) Expect(err).NotTo(HaveOccurred()) - s, err := m.GetStream(1) - Expect(err).NotTo(HaveOccurred()) + s, exists := m.GetStream(1) + Expect(exists).To(BeTrue()) Expect(s).To(BeNil()) }) @@ -38,8 +38,8 @@ var _ = Describe("Streams Map", func() { It("stores streams", func() { err := m.PutStream(&stream{streamID: 5}) Expect(err).NotTo(HaveOccurred()) - s, err := m.GetStream(5) - Expect(err).NotTo(HaveOccurred()) + s, exists := m.GetStream(5) + Expect(exists).To(BeTrue()) Expect(s.streamID).To(Equal(protocol.StreamID(5))) })