Skip to content

Commit

Permalink
Merge pull request dunglas#173 from dunglas/test-raw-string
Browse files Browse the repository at this point in the history
Add a test prooving that raw strings work
  • Loading branch information
dunglas authored Oct 9, 2019
2 parents 57d89c5 + 221a9dc commit a7887c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions hub/subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
bolt "go.etcd.io/bbolt"
)
Expand Down Expand Up @@ -110,6 +111,7 @@ func TestSubscribeNoTopic(t *testing.T) {
}

func testSubscribe(numberOfSubscribers int, t *testing.T) {
log.SetLevel(log.DebugLevel)
hub := createAnonymousDummy()
hub.Start()

Expand Down Expand Up @@ -139,6 +141,10 @@ func testSubscribe(numberOfSubscribers int, t *testing.T) {
Topics: []string{"http://example.com/hub?topic=faulty{iri"},
Event: Event{Data: "Faulty IRI", ID: "d"},
})
hub.updates <- newSerializedUpdate(&Update{
Topics: []string{"string"},
Event: Event{Data: "string", ID: "e"},
})

hub.Stop()
return
Expand All @@ -150,14 +156,14 @@ func testSubscribe(numberOfSubscribers int, t *testing.T) {
for i := 0; i < numberOfSubscribers; i++ {
go func(w2 *sync.WaitGroup) {
defer w2.Done()
req := httptest.NewRequest("GET", "http://example.com/hub?topic=http://example.com/books/1&topic=http://example.com/reviews/{id}&topic=http://example.com/hub?topic=faulty{iri", nil)
req := httptest.NewRequest("GET", "http://example.com/hub?topic=http://example.com/books/1&topic=string&topic=http://example.com/reviews/{id}&topic=http://example.com/hub?topic=faulty{iri", nil)
w := newCloseNotifyingRecorder()
hub.SubscribeHandler(w, req)

if t != nil {
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, ":\nid: b\ndata: Hello World\n\nid: c\ndata: Great\n\nid: d\ndata: Faulty IRI\n\n", w.Body.String())
assert.Equal(t, ":\nid: b\ndata: Hello World\n\nid: c\ndata: Great\n\nid: d\ndata: Faulty IRI\n\nid: e\ndata: string\n\n", w.Body.String())
}
}(&wg)
}
Expand Down
3 changes: 2 additions & 1 deletion public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
}, null, 2);

document.getElementById('subscribeTopicsExamples').innerText = `${origin}/demo/novels/{id}.jsonld
${defaultTopic}`;
${defaultTopic}
foo`;
});

// Discover
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h1 class="title is-2">Subscribe</h1>
</div>

<p class="help">
One <a href="https://tools.ietf.org/html/rfc6570">URI template</a> per line (<a href="https://uri-template-tester.mercure.rocks/">try the tester</a>).<br>
One <a href="https://tools.ietf.org/html/rfc6570">URI template</a> or string per line (<a href="https://uri-template-tester.mercure.rocks/">try the tester</a>).<br>
Examples:
<pre><code id="subscribeTopicsExamples"></code></pre><br>
</p>
Expand Down

0 comments on commit a7887c0

Please sign in to comment.