You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_repo_languages_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "net/url"
  8. "testing"
  9. "time"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestRepoLanguages(t *testing.T) {
  13. onGiteaRun(t, func(t *testing.T, u *url.URL) {
  14. session := loginUser(t, "user2")
  15. // Request editor page
  16. req := NewRequest(t, "GET", "/user2/repo1/_new/master/")
  17. resp := session.MakeRequest(t, req, http.StatusOK)
  18. doc := NewHTMLParser(t, resp.Body)
  19. lastCommit := doc.GetInputValueByName("last_commit")
  20. assert.NotEmpty(t, lastCommit)
  21. // Save new file to master branch
  22. req = NewRequestWithValues(t, "POST", "/user2/repo1/_new/master/", map[string]string{
  23. "_csrf": doc.GetCSRF(),
  24. "last_commit": lastCommit,
  25. "tree_path": "test.go",
  26. "content": "package main",
  27. "commit_choice": "direct",
  28. })
  29. session.MakeRequest(t, req, http.StatusFound)
  30. // let gitea calculate language stats
  31. time.Sleep(time.Second)
  32. // Save new file to master branch
  33. req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/languages")
  34. resp = session.MakeRequest(t, req, http.StatusOK)
  35. var languages map[string]int64
  36. DecodeJSON(t, resp, &languages)
  37. assert.InDeltaMapValues(t, map[string]int64{"Go": 12}, languages, 0)
  38. })
  39. }