Home / Function/ TestContextNegotiationWithPROTOBUF() — gin Function Reference

TestContextNegotiationWithPROTOBUF() — gin Function Reference

Architecture documentation for the TestContextNegotiationWithPROTOBUF() function in context_test.go from the gin codebase.

Entity Profile

Relationship Graph

Source Code

context_test.go lines 1679–1703

func TestContextNegotiationWithPROTOBUF(t *testing.T) {
	w := httptest.NewRecorder()
	c, _ := CreateTestContext(w)
	c.Request = httptest.NewRequest(http.MethodPost, "/", nil)

	reps := []int64{int64(1), int64(2)}
	label := "test"
	data := &testdata.Test{
		Label: &label,
		Reps:  reps,
	}

	c.Negotiate(http.StatusCreated, Negotiate{
		Offered: []string{MIMEPROTOBUF, MIMEJSON, MIMEXML},
		Data:    data,
	})

	// Marshal original data for comparison
	protoData, err := proto.Marshal(data)
	require.NoError(t, err)

	assert.Equal(t, http.StatusCreated, w.Code)
	assert.Equal(t, string(protoData), w.Body.String())
	assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type"))
}

Domain

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free