コード例 #1
0
func TestRemoveUser(t *testing.T) {
	err := store.AddUser(&User{Username: "******"})
	assert.Nil(t, err)
	err = store.RemoveUser("remove_me")
	assert.Nil(t, err)
	assert.Nil(t, store.GetUser("remove_me"))

	err = store.RemoveUser("not_a_user")
	assert.Equal(t, ErrUserNotFound, err)
}
コード例 #2
0
func TestRemoveSetting(t *testing.T) {
	r := createRouter()

	// It should return 400 if the id is invalid
	req := testRequest(r, "DELETE", "/account/settings/cake", nil)
	req.Header.Set("Authorization", "token")
	assert.Equal(t, 400, req.send().Code)

	// It should return 404 when the setting does not exist
	req.URL.Path = "/account/settings/1881"
	assert.Equal(t, 404, req.send().Code)

	// It should return 200 when removing a setting
	req.URL.Path = "/account/settings/1"
	assert.Equal(t, 200, req.send().Code)

	// It should have removed the setting
	req.Method = "GET"
	req.URL.Path = "/account/settings"
	res := req.send()
	assert.Equal(t, 200, res.Code)
	settings := []Setting{}
	err := json.Unmarshal(res.Body.Bytes(), &settings)
	assert.Nil(t, err)

	for _, setting := range settings {
		if setting.ID == 1 {
			t.Error("Setting with ID 1 did not get removed")
		}
	}
}
コード例 #3
0
func TestRouterMultiRoute(t *testing.T) {
	e := New()
	r := e.router

	// Routes
	r.Add(GET, "/users", func(c *Context) error {
		c.Set("path", "/users")
		return nil
	}, e)
	r.Add(GET, "/users/:id", func(c *Context) error {
		return nil
	}, e)
	c := NewContext(nil, nil, e)

	// Route > /users
	h, _ := r.Find(GET, "/users", c)
	if assert.NotNil(t, h) {
		h(c)
		assert.Equal(t, "/users", c.Get("path"))
	}

	// Route > /users/:id
	h, _ = r.Find(GET, "/users/1", c)
	if assert.NotNil(t, h) {
		assert.Equal(t, "1", c.P(0))
	}

	// Route > /user
	h, _ = r.Find(GET, "/user", c)
	assert.Nil(t, h)
}
コード例 #4
0
func checkSettings(t *testing.T, req testReq) []Setting {
	req.Method = "GET"
	res := req.send()
	assert.Equal(t, 200, res.Code)
	settings := []Setting{}
	err := json.Unmarshal(res.Body.Bytes(), &settings)
	assert.Nil(t, err)
	return settings
}
コード例 #5
0
func checkEvents(t *testing.T, req testReq) events {
	now := time.Now().Unix()
	res := req.send()
	assert.Equal(t, 200, res.Code)
	data := events{}
	err := json.Unmarshal(res.Body.Bytes(), &data)
	assert.Nil(t, err)
	assert.True(t, data.Timestamp >= now)
	return data
}
コード例 #6
0
func TestAddUser(t *testing.T) {
	err := store.AddUser(&User{
		Username: "******",
		Password: "******",
	})
	assert.Nil(t, err)

	user := store.GetUser("added")
	assert.NotNil(t, user)
	assert.Equal(t, "added", user.Username)
	assert.NotEmpty(t, user.Password)

	err = store.AddUser(&User{Username: "******"})
	assert.Equal(t, ErrUsernameUnavailable, err)
}
コード例 #7
0
func TestRouterTwoParam(t *testing.T) {
	e := New()
	r := e.router
	r.Add(GET, "/users/:uid/files/:fid", func(*Context) error {
		return nil
	}, e)
	c := NewContext(nil, nil, e)

	h, _ := r.Find(GET, "/users/1/files/1", c)
	if assert.NotNil(t, h) {
		assert.Equal(t, "1", c.P(0))
		assert.Equal(t, "1", c.P(1))
	}

	h, _ = r.Find(GET, "/users/1", c)
	assert.Nil(t, h)
}
コード例 #8
0
func TestEvents(t *testing.T) {
	err := store.AddEvents([]Event{
		Event{
			Type:              10,
			EpisodeID:         1,
			PositionTS:        134,
			ClientTS:          100,
			ConcurrentOrder:   0,
			ClientName:        "Castcloud",
			ClientDescription: "oink",
		},
		Event{
			Type:              10,
			EpisodeID:         1,
			PositionTS:        112,
			ClientTS:          50,
			ConcurrentOrder:   0,
			ClientName:        "Castcloud",
			ClientDescription: "oink",
		},
	}, 2, "evuuid1")
	assert.Nil(t, err)

	events := store.GetEvents(2, 100, "")
	assert.Len(t, events, 0)

	events = store.GetEvents(2, 99, "")
	assert.Len(t, events, 1)
	assert.Equal(t, 10, events[0].Type)
	assert.Equal(t, 134, events[0].PositionTS)

	events = store.GetEvents(2, 99, "evuuid1")
	assert.Len(t, events, 0)

	events = store.GetEvents(2, 99, "nope")
	assert.Len(t, events, 1)

	events = store.GetEvents(2, 25, "")
	assert.Len(t, events, 2)
	assert.Equal(t, 112, events[0].PositionTS)
}
コード例 #9
0
func TestCrawlFetch(t *testing.T) {
	// It should return the cast
	cast := <-crawl.fetch(testRSS)
	assert.NotNil(t, cast)
	assert.Equal(t, testRSS, cast.URL)
	assert.Equal(t, "BSD Now HD", cast.Name)

	// It should return nil if the url is bad
	assert.Nil(t, <-crawl.fetch("so_bad"))

	// It should return nil if the the status is not 200
	assert.Nil(t, <-crawl.fetch(testServer.URL))

	// It should return nil if it cant parse things
	assert.Nil(t, <-crawl.fetch(testServer.URL+"/notxml"))

	// It should return nil if the xml is not a proper feed
	assert.Nil(t, <-crawl.fetch(testServer.URL+"/notfeed"))
	assert.Nil(t, <-crawl.fetch(testServer.URL+"/badrss"))
	assert.Nil(t, <-crawl.fetch(testServer.URL+"/badatom"))
}
コード例 #10
0
func TestCreateToken(t *testing.T) {
	token, err := createToken(32)
	assert.Nil(t, err)
	assert.Len(t, token, 64)
}