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.

utils_test.go 978B

12345678910111213141516171819202122232425262728293031
  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 git
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestRefEndName(t *testing.T) {
  10. // Test branch names (with and without slash).
  11. assert.Equal(t, "foo", RefEndName("refs/heads/foo"))
  12. assert.Equal(t, "feature/foo", RefEndName("refs/heads/feature/foo"))
  13. // Test tag names (with and without slash).
  14. assert.Equal(t, "foo", RefEndName("refs/tags/foo"))
  15. assert.Equal(t, "release/foo", RefEndName("refs/tags/release/foo"))
  16. // Test commit hashes.
  17. assert.Equal(t, "c0ffee", RefEndName("c0ffee"))
  18. }
  19. func TestRefURL(t *testing.T) {
  20. repoURL := "/user/repo"
  21. assert.Equal(t, repoURL+"/src/branch/foo", RefURL(repoURL, "refs/heads/foo"))
  22. assert.Equal(t, repoURL+"/src/tag/foo", RefURL(repoURL, "refs/tags/foo"))
  23. assert.Equal(t, repoURL+"/src/commit/c0ffee", RefURL(repoURL, "c0ffee"))
  24. }