MCPcopy Index your code
hub / github.com/coder/coder / TestPostFiles

Function TestPostFiles

coderd/files_test.go:26–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestPostFiles(t *testing.T) {
27 t.Parallel()
28
29 buildZipWithFile := func(t *testing.T, name string, writeContents func(w io.Writer) error) []byte {
30 t.Helper()
31
32 var zipBytes bytes.Buffer
33 zw := zip.NewWriter(&zipBytes)
34 w, err := zw.Create(name)
35 require.NoError(t, err)
36 require.NoError(t, writeContents(w))
37 require.NoError(t, zw.Close())
38
39 return zipBytes.Bytes()
40 }
41
42 // Single instance shared across all sub-tests. Each sub-test
43 // creates independent resources with unique IDs so parallel
44 // execution is safe.
45 client := coderdtest.New(t, nil)
46 _ = coderdtest.CreateFirstUser(t, client)
47 t.Run("BadContentType", func(t *testing.T) {
48 t.Parallel()
49 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
50 defer cancel()
51
52 _, err := client.Upload(ctx, "bad", bytes.NewReader([]byte{'a'}))
53 require.Error(t, err)
54 })
55
56 t.Run("Insert", func(t *testing.T) {
57 t.Parallel()
58 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
59 defer cancel()
60
61 _, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(make([]byte, 1024)))
62 require.NoError(t, err)
63 })
64
65 t.Run("InsertWindowsZip", func(t *testing.T) {
66 t.Parallel()
67 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
68 defer cancel()
69
70 _, err := client.Upload(ctx, "application/x-zip-compressed", bytes.NewReader(archivetest.TestZipFileBytes()))
71 require.NoError(t, err)
72 })
73
74 t.Run("InsertAlreadyExists", func(t *testing.T) {
75 t.Parallel()
76 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
77 defer cancel()
78
79 data := make([]byte, 1024)
80 _, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
81 require.NoError(t, err)
82 _, err = client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
83 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
TestZipFileBytesFunction · 0.92
HelperMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.65
UploadMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected