// title: kind list // path: /events/kinds // method: GET // produce: application/json // responses: // 200: OK // 204: No content func kindList(w http.ResponseWriter, r *http.Request, t auth.Token) error { kinds, err := event.GetKinds() if err != nil { return err } if len(kinds) == 0 { w.WriteHeader(http.StatusNoContent) return nil } w.Header().Add("Content-Type", "application/json") return json.NewEncoder(w).Encode(kinds) }
func (s *S) TestGetKinds(c *check.C) { _, err := event.New(&event.Opts{ Target: event.Target{Type: "app", Value: "myapp"}, Kind: permission.PermAppUpdateEnvSet, Owner: s.token, Allowed: event.Allowed(permission.PermAppReadEvents), }) c.Assert(err, check.IsNil) kinds, err := event.GetKinds() c.Assert(err, check.IsNil) c.Assert(kinds, check.HasLen, 1) expected := []event.Kind{ {Type: "permission", Name: "app.update.env.set"}, } c.Assert(kinds, check.DeepEquals, expected) }