github.com/x-motemen/ghq@v1.6.1/go_import_test.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestDetectVCSAndRepoURL(t *testing.T) {
     9  	input := `<html>
    10  <head>
    11  <meta name="go-import" content="gopkg.in/yaml.v2 mod https://gopkg.in/yaml.v2">
    12  <meta name="go-import" content="gopkg.in/yaml.v2 git https://gopkg.in/yaml.v2">
    13  <meta name="go-source" content="gopkg.in/yaml.v2 _ https://github.com/go-yaml/yaml/tree/v2.2.2{/dir} https://github.com/go-yaml/yaml/blob/v2.2.2{/dir}/{file}#L{line}">
    14  </head>
    15  <body>
    16  go get gopkg.in/yaml.v2
    17  </body>
    18  </html>`
    19  
    20  	vcs, u, err := detectVCSAndRepoURL(strings.NewReader(input))
    21  	if vcs != "git" {
    22  		t.Errorf("want: %q, got: %q", "git", vcs)
    23  	}
    24  	expectedURL := "https://gopkg.in/yaml.v2"
    25  	if u.String() != expectedURL {
    26  		t.Errorf("want: %q, got: %q", expectedURL, u.String())
    27  	}
    28  	if err != nil {
    29  		t.Errorf("something went wrong: %s", err)
    30  	}
    31  }