-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastream.go
54 lines (45 loc) · 1.87 KB
/
datastream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package tests
import (
"bytes"
"encoding/json"
"github.com/revel/revel"
"github.com/stsmedia/thingbricks/app/models"
"net/http"
)
type DataStreamTests struct {
revel.TestSuite
}
const (
datastream = "/datastreams"
)
func (t *DataStreamTests) TestCreateDataStream() {
body, _ := json.Marshal(&models.DataStream{Name: "foo1", Description: "Test Stream"})
t.Post(account+"/1"+project+"/1"+datastreamgroup+"/1"+datastream, contentType, bytes.NewBufferString(string(body)))
t.AssertOk()
}
func (t *DataStreamTests) TestCreateDataStreamInvalidJson() {
t.Post(account+"/1"+project+"/1"+datastreamgroup+"/1"+datastream, contentType, bytes.NewBufferString("{\"name1\":\"foo\"}"))
t.AssertStatus(http.StatusNotAcceptable)
t.AssertContains("Data stream name required")
}
func (t *DataStreamTests) TestUpdateDataStream() {
body, _ := json.Marshal(&models.DataStream{Id: 1, Name: "foo2", Description: "Test Project 1"})
t.Put(account+"/1"+project+"/1"+datastreamgroup+"/1"+datastream+"/1", contentType, bytes.NewBufferString(string(body)))
t.AssertOk()
t.AssertContains("foo2")
}
func (t *DataStreamTests) TestUpdateDataStreamNotMatchingIds() {
body, _ := json.Marshal(&models.DataStream{Id: 2, Name: "foo", Description: "bla"})
t.Put(account+"/1"+project+"/1"+datastreamgroup+"/1"+datastream+"/1", contentType, bytes.NewBufferString(string(body)))
t.AssertStatus(http.StatusNotAcceptable)
t.AssertContains("Entity ID and URL ID don't match")
}
func (t *DataStreamTests) TestUpdateDataStreamInvalidJson() {
t.Put(account+"/1"+project+"/1"+datastreamgroup+"/1"+datastream+"/1", contentType, bytes.NewBufferString("{\"id\":1, \"name1\":\"foo\"}"))
t.AssertStatus(http.StatusNotAcceptable)
t.AssertContains("Data stream name required")
}
func (t *DataStreamTests) TestDeleteDataStream() {
t.Delete(account + "/1" + project + "/1" + datastreamgroup + "/1" + datastream + "/1")
t.AssertOk()
}