MCPcopy Create free account
hub / github.com/GetStream/stream-cli / TestFileUploadAndDelete

Function TestFileUploadAndDelete

pkg/cmd/chat/file/file_test.go:16–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestFileUploadAndDelete(t *testing.T) {
17 cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
18 ch := test.InitChannel(t)
19 u := test.CreateUser()
20
21 tmpfile, err := os.CreateTemp("", "*.txt")
22 require.NoError(t, err)
23
24 err = os.WriteFile(tmpfile.Name(), []byte("hello\nworld\n"), 0o644)
25 require.NoError(t, err)
26
27 t.Cleanup(func() {
28 _ = tmpfile.Close()
29 _ = os.Remove(tmpfile.Name())
30 test.DeleteUser(u)
31 test.DeleteChannel(ch)
32 })
33
34 cmd.SetArgs([]string{"upload-file", "-t", "messaging", "-i", ch, "-u", u, "--file", tmpfile.Name()})
35 _, err = cmd.ExecuteC()
36 require.NoError(t, err)
37 stdOut := cmd.OutOrStdout().(*bytes.Buffer).String()
38 require.Contains(t, stdOut, "Successfully uploaded file")
39
40 // The stdout looks like this:
41 // Successfully uploaded file: http://example.org/snippet.txt\n
42 url := strings.Split(stdOut, ": ")[1]
43 url = strings.TrimSuffix(url, "\n")
44 cmd.SetArgs([]string{"delete-file", "-t", "messaging", "-i", ch, "-u", u, "--file-url", url})
45 _, err = cmd.ExecuteC()
46 require.NoError(t, err)
47}
48
49func TestImageUploadAndDelete(t *testing.T) {
50 cmd := test.GetRootCmdWithSubCommands(NewCmds()...)

Callers

nothing calls this directly

Calls 8

InitChannelFunction · 0.92
CreateUserFunction · 0.92
DeleteUserFunction · 0.92
DeleteChannelFunction · 0.92
RemoveMethod · 0.80
StringMethod · 0.80
NewCmdsFunction · 0.70

Tested by

no test coverage detected