gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package convert
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestToCorrectPageSize(t *testing.T) {
  9. assert.Equal(t, 30, ToCorrectPageSize(0))
  10. assert.Equal(t, 30, ToCorrectPageSize(-10))
  11. assert.Equal(t, 20, ToCorrectPageSize(20))
  12. assert.Equal(t, 50, ToCorrectPageSize(100))
  13. }
  14. func TestToGitServiceType(t *testing.T) {
  15. tc := []struct {
  16. typ string
  17. enum int
  18. }{{
  19. typ: "trash", enum: 1,
  20. }, {
  21. typ: "github", enum: 2,
  22. }, {
  23. typ: "gitea", enum: 3,
  24. }, {
  25. typ: "gitlab", enum: 4,
  26. }, {
  27. typ: "gogs", enum: 5,
  28. }, {
  29. typ: "onedev", enum: 6,
  30. }, {
  31. typ: "gitbucket", enum: 7,
  32. }, {
  33. typ: "codebase", enum: 8,
  34. }, {
  35. typ: "codecommit", enum: 9,
  36. }}
  37. for _, test := range tc {
  38. assert.EqualValues(t, test.enum, ToGitServiceType(test.typ))
  39. }
  40. }