github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/golang/project/project_test.go (about)

     1  package project
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestParseModuleName(t *testing.T) {
     8  	expected := "github.com/jfrog/go-example"
     9  	tests := []struct {
    10  		name     string
    11  		content  string
    12  		expected string
    13  	}{
    14  		{"moduleNameWithoutQuotationMarks", `
    15  
    16  module github.com/jfrog/go-example
    17  
    18  go 1.14
    19  
    20  require (
    21          github.com/Sirupsen/logrus v1.0.6
    22          golang.org/x/crypto v0.0.0-20180802221240-56440b844dfe // indirect
    23          golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef // indirect
    24          rsc.io/quote v1.5.2
    25  )
    26  	`, expected},
    27  		{"ModuleNameWithQuotationMarks", `
    28  
    29  module "github.com/jfrog/go-example"
    30  
    31  require (
    32          github.com/Sirupsen/logrus v1.0.6
    33          golang.org/x/crypto v0.0.0-20180802221240-56440b844dfe // indirect
    34          golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef // indirect
    35          rsc.io/quote v1.5.2
    36  )
    37  	`, expected},
    38  		{"ModuleNameWithoutSlash", `
    39  
    40  module go4.org
    41  
    42  require (
    43          github.com/Sirupsen/logrus v1.0.6
    44          golang.org/x/crypto v0.0.0-20180802221240-56440b844dfe // indirect
    45          golang.org/x/sys v0.0.0-20180802203216-0ffbfd41fbef // indirect
    46          rsc.io/quote v1.5.2
    47  )
    48  	`, "go4.org"},
    49  	}
    50  
    51  	for _, test := range tests {
    52  		t.Run(test.name, func(t *testing.T) {
    53  			actual, err := parseModuleName(test.content)
    54  
    55  			if err != nil {
    56  				t.Error(err)
    57  			}
    58  
    59  			if actual != test.expected {
    60  				t.Errorf("Expected: %s, got: %s.", test.expected, actual)
    61  			}
    62  		})
    63  	}
    64  }