Home / File/ context_file_test.go — gin Source File

context_file_test.go — gin Source File

Architecture documentation for context_file_test.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go GinCore Context 1 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  fa0cdbd7_ab43_fdb7_04e2_ac002df4c609["context_file_test.go"]
  08248871_dc00_f330_15ef_4a0fbf2bafbb["http"]
  fa0cdbd7_ab43_fdb7_04e2_ac002df4c609 --> 08248871_dc00_f330_15ef_4a0fbf2bafbb
  style fa0cdbd7_ab43_fdb7_04e2_ac002df4c609 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package gin

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"
)

// TestContextFileSimple tests the Context.File() method with a simple case
func TestContextFileSimple(t *testing.T) {
	// Test serving an existing file
	testFile := "testdata/test_file.txt"
	w := httptest.NewRecorder()
	c, _ := CreateTestContext(w)
	c.Request = httptest.NewRequest(http.MethodGet, "/test", nil)

	c.File(testFile)

	assert.Equal(t, http.StatusOK, w.Code)
	assert.Contains(t, w.Body.String(), "This is a test file")
	assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
}

// TestContextFileNotFound tests serving a non-existent file
func TestContextFileNotFound(t *testing.T) {
	w := httptest.NewRecorder()
	c, _ := CreateTestContext(w)
	c.Request = httptest.NewRequest(http.MethodGet, "/test", nil)

	c.File("non_existent_file.txt")

	assert.Equal(t, http.StatusNotFound, w.Code)
}

Domain

Subdomains

Dependencies

  • http

Frequently Asked Questions

What does context_file_test.go do?
context_file_test.go is a source file in the gin codebase, written in go. It belongs to the GinCore domain, Context subdomain.
What functions are defined in context_file_test.go?
context_file_test.go defines 2 function(s): TestContextFileNotFound, TestContextFileSimple.
What does context_file_test.go depend on?
context_file_test.go imports 1 module(s): http.
Where is context_file_test.go in the architecture?
context_file_test.go is located at context_file_test.go (domain: GinCore, subdomain: Context).

Analyze Your Own Codebase

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

Try Supermodel Free