labelDeps builds a server whose ModifyMessageLabels fake maps message ids to outcomes: "msg_cap" → cap exceeded, "msg_missing" → not found, anything else → echo the add list as the post-update set.
()
| 14 | // outcomes: "msg_cap" → cap exceeded, "msg_missing" → not found, anything else |
| 15 | // → echo the add list as the post-update set. |
| 16 | func labelDeps() Deps { |
| 17 | return Deps{ |
| 18 | Authenticator: func(r *http.Request) (*identity.User, error) { |
| 19 | if r.Header.Get("Authorization") == "Bearer good" { |
| 20 | return &identity.User{ID: "u_1", Email: "owner@acme.com"}, nil |
| 21 | } |
| 22 | return nil, errors.New("unauthorized") |
| 23 | }, |
| 24 | GetAgent: func(ctx context.Context, address string) (*identity.AgentIdentity, error) { |
| 25 | if address == "support@acme.com" { |
| 26 | a := sampleAgent() |
| 27 | return &a, nil |
| 28 | } |
| 29 | return nil, errors.New("not found") |
| 30 | }, |
| 31 | ModifyMessageLabels: func(ctx context.Context, messageID, agentID string, add, remove []string) ([]string, error) { |
| 32 | if agentID != "support@acme.com" { |
| 33 | return nil, errors.New("unexpected agent") |
| 34 | } |
| 35 | switch messageID { |
| 36 | case "msg_cap": |
| 37 | return nil, identity.ErrLabelLimitExceeded |
| 38 | case "msg_missing": |
| 39 | return nil, identity.ErrMessageNotFound |
| 40 | default: |
| 41 | return add, nil |
| 42 | } |
| 43 | }, |
| 44 | Legacy: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTeapot) }), |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestUpdateMessageLabels_AddRemove(t *testing.T) { |
| 49 | srv := httptest.NewServer(New(labelDeps())) |
no test coverage detected