Golang Context.Request Examples

Golang Context.Request - 5 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.Request extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
func Test_ParseAppendSeriesListRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"SeriesID": 2
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseAppendSeriesListRequest(&ginCtx)
	if err != nil {
		t.Fatal(err)
	}

	expect := SeriesListRequestData{
		SeriesID: 2,
	}

	if expect.SeriesID != s.SeriesID {
		m := fmt.Sprintf("Expect %v was %v", expect, s)
		t.Fatal(m)
	}

}
Example #2
0
func Test_ParseUserRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"Name": "name",
			"Password": "password"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	u, err := ParseNewUserRequest(&ginCtx)

	expect := User{
		Name:     "name",
		Password: "password",
	}

	if err := EqualUser(expect, u); err != nil {
		t.Fatal(err)
	}

}
Example #3
0
func Test_ParseSeriesRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"Title": "Title",
			"Image": "Image"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseNewSeriesRequest(&ginCtx)

	expect := Series{
		Title: "Title",
		Image: "Image",
	}

	if err := EqualSeries(expect, s); err != nil {
		t.Fatal(err)
	}

}
Example #4
0
func Test_ParseUpdateLastWatchedRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"UserID": 1,
			"SeriesID": 2,
			"Session": 3,
			"Episode": 4
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseUpdateLastWatchedRequest(&ginCtx)
	if err != nil {
		t.Fatal(err)
	}

	expect := LastWatched{
		SeriesID: 2,
		Session:  3,
		Episode:  4,
	}

	if expect.SeriesID != s.SeriesID ||
		expect.Session != s.Session ||
		expect.Episode != s.Episode {
		m := fmt.Sprintf("Expect %v was %v", expect, s)
		t.Fatal(m)
	}

}
Example #5
0
func Test_ParseNewSeriesRequest_FailMissingFields(t *testing.T) {
	data := `
	{
		"Data": {
			"Title": "Title"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	_, err = ParseNewSeriesRequest(&ginCtx)
	expect := NewMissingFieldError("Image")
	if err.Error() != expect.Error() {
		t.Fatal("Expect", expect, "was", err)
	}
}