MCPcopy
hub / github.com/mattermost/mattermost / TestClient4SetToken

Function TestClient4SetToken

server/public/model/client4_test.go:90–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestClient4SetToken(t *testing.T) {
91 expected := model.NewId()
92
93 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
94 authHeader := r.Header.Get(model.HeaderAuth)
95
96 token := strings.Split(authHeader, model.HeaderBearer)
97
98 if len(token) < 2 {
99 t.Errorf("wrong authorization header format, got %s, expected: %s %s", authHeader, model.HeaderBearer, expected)
100 }
101
102 assert.Equal(t, expected, strings.TrimSpace(token[1]))
103
104 var user model.User
105 err := json.NewEncoder(w).Encode(&user)
106 assert.NoError(t, err)
107 }))
108
109 client := model.NewAPIv4Client(server.URL)
110 client.SetToken(expected)
111
112 _, resp, err := client.GetMe(context.Background(), "")
113 assert.NoError(t, err)
114 assert.Equal(t, http.StatusOK, resp.StatusCode)
115}
116
117func TestClient4RequestCancellation(t *testing.T) {
118 t.Run("cancel before making the reqeust", func(t *testing.T) {

Callers

nothing calls this directly

Calls 7

EncodeMethod · 0.80
SetTokenMethod · 0.80
GetMeMethod · 0.80
GetMethod · 0.65
ErrorfMethod · 0.65
EqualMethod · 0.45
NoErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…