vcs_test.go 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package vcs
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestParsing(t *testing.T) {
  7. type source struct {
  8. URL string
  9. Branch string
  10. Protocols []string
  11. }
  12. urls := []string{
  13. "git+https://github.com/neovim/neovim.git",
  14. "git://github.com/jguer/yay.git#branch=master",
  15. "git://github.com/davidgiven/ack",
  16. "git://github.com/jguer/yay.git#tag=v3.440",
  17. "git://github.com/jguer/yay.git#commit=e5470c88c6e2f9e0f97deb4728659ffa70ef5d0c",
  18. "a+b+c+d+e+f://github.com/jguer/yay.git#branch=foo",
  19. }
  20. sources := []source{
  21. {"github.com/neovim/neovim.git", "HEAD", []string{"https"}},
  22. {"github.com/jguer/yay.git", "master", []string{"git"}},
  23. {"github.com/davidgiven/ack", "HEAD", []string{"git"}},
  24. {"", "", nil},
  25. {"", "", nil},
  26. {"", "", nil},
  27. }
  28. for n, url := range urls {
  29. url, branch, protocols := parseSource(url)
  30. compare := sources[n]
  31. assert.Equal(t, compare.URL, url)
  32. assert.Equal(t, compare.Branch, branch)
  33. assert.Equal(t, compare.Protocols, protocols)
  34. }
  35. }