Skip to content
Permalink
Browse files

Merge pull request #173 from dunglas/test-raw-string

Add a test prooving that raw strings work
  • Loading branch information...
dunglas committed Oct 9, 2019
2 parents 57d89c5 + 221a9dc commit a7887c0569b18bae8d8fce3750e3b29b99060286
Showing with 11 additions and 4 deletions.
  1. +8 −2 hub/subscribe_test.go
  2. +2 −1 public/app.js
  3. +1 −1 public/index.html
@@ -8,6 +8,7 @@ import (
"testing"
"time"

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

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

@@ -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
@@ -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)
}
@@ -42,7 +42,8 @@
}, null, 2);

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

// Discover
@@ -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>

0 comments on commit a7887c0

Please sign in to comment.
You can’t perform that action at this time.