MCPcopy Create free account
hub / github.com/coder/agentapi / TestServer_UploadFiles

Function TestServer_UploadFiles

lib/httpapi/server_test.go:661–814  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

659}
660
661func TestServer_UploadFiles(t *testing.T) {
662 t.Parallel()
663 ctx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
664 srv, err := httpapi.NewServer(ctx, httpapi.ServerConfig{
665 AgentType: msgfmt.AgentTypeClaude,
666 AgentIO: nil,
667 Port: 0,
668 ChatBasePath: "/chat",
669 AllowedHosts: []string{"*"},
670 AllowedOrigins: []string{"*"},
671 })
672 require.NoError(t, err)
673 tsServer := httptest.NewServer(srv.Handler())
674 t.Cleanup(tsServer.Close)
675
676 cases := []struct {
677 name string
678 filename string
679 fileContent string
680 expectedStatusCode int
681 expectFilePath bool
682 }{
683 {
684 name: "upload jpeg file",
685 filename: "test.jpeg",
686 fileContent: "Hello, world!",
687 expectedStatusCode: http.StatusOK,
688 expectFilePath: true,
689 },
690 {
691 name: "upload empty file",
692 filename: "empty.txt",
693 fileContent: "",
694 expectedStatusCode: http.StatusOK,
695 expectFilePath: true,
696 },
697 {
698 name: "upload binary file",
699 filename: "test.bin",
700 fileContent: "\x00\x01\x02\x03\xFF",
701 expectedStatusCode: http.StatusOK,
702 expectFilePath: true,
703 },
704 {
705 name: "upload file with special characters in name",
706 filename: "test file (1).txt",
707 fileContent: "content",
708 expectedStatusCode: http.StatusOK,
709 expectFilePath: true,
710 },
711 {
712 name: "upload file with absolute path filename",
713 filename: "/tmp/absolute-path-file.txt",
714 fileContent: "absolute path content",
715 expectedStatusCode: http.StatusOK,
716 expectFilePath: true,
717 },
718 {

Callers

nothing calls this directly

Calls 6

HandlerMethod · 0.95
WithLoggerFunction · 0.92
NewServerFunction · 0.92
CloseMethod · 0.80
WriteMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected