gitea源码

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. api "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/modules/test"
  10. "code.gitea.io/gitea/routers"
  11. "code.gitea.io/gitea/tests"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestNodeinfo(t *testing.T) {
  15. defer tests.PrepareTestEnv(t)()
  16. defer test.MockVariableValue(&setting.Federation.Enabled, true)()
  17. defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
  18. req := NewRequest(t, "GET", "/api/v1/nodeinfo")
  19. resp := MakeRequest(t, req, http.StatusOK)
  20. VerifyJSONSchema(t, resp, "nodeinfo_2.1.json")
  21. var nodeinfo api.NodeInfo
  22. DecodeJSON(t, resp, &nodeinfo)
  23. assert.True(t, nodeinfo.OpenRegistrations)
  24. assert.Equal(t, "gitea", nodeinfo.Software.Name)
  25. assert.Equal(t, 29, nodeinfo.Usage.Users.Total)
  26. assert.Equal(t, 22, nodeinfo.Usage.LocalPosts)
  27. assert.Equal(t, 3, nodeinfo.Usage.LocalComments)
  28. }