github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/go/go_test.go (about)

     1  package _go
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/cobalt77/jfrog-client-go/utils"
     9  )
    10  
    11  func TestCreateUrlPath(t *testing.T) {
    12  
    13  	tests := []struct {
    14  		name        string
    15  		extension   string
    16  		moduleId    string
    17  		version     string
    18  		props       string
    19  		url         string
    20  		expectedUrl string
    21  	}{
    22  		{"withBuildProperties", ".zip", "github.com/jfrog/test", "v1.1.1", "build.name=a;build.number=1", "http://test.url/", "http://test.url//github.com/jfrog/test/@v/v1.1.1.zip;build.name=a;build.number=1"},
    23  		{"withoutBuildProperties", ".zip", "github.com/jfrog/test", "v1.1.1", "", "http://test.url/", "http://test.url//github.com/jfrog/test/@v/v1.1.1.zip"},
    24  		{"withoutBuildPropertiesModExtension", ".mod", "github.com/jfrog/test", "v1.1.1", "", "http://test.url/", "http://test.url//github.com/jfrog/test/@v/v1.1.1.mod"},
    25  	}
    26  	for _, test := range tests {
    27  		t.Run(test.name, func(t *testing.T) {
    28  			CreateUrlPath(test.moduleId, test.version, test.props, test.extension, &test.url)
    29  			if !strings.EqualFold(test.url, test.expectedUrl) {
    30  				t.Error("Expected:", test.expectedUrl, "Got:", test.url)
    31  			}
    32  		})
    33  	}
    34  }
    35  
    36  func TestShouldUseHeaders(t *testing.T) {
    37  	tests := []struct {
    38  		artifactoryVersion string
    39  		expectedResult     string
    40  	}{
    41  		{"6.5.0", "*_go.publishWithMatrixParams"},
    42  		{"6.2.0", "*_go.publishWithHeader"},
    43  		{"5.9.0", "*_go.publishWithHeader"},
    44  		{"6.0.0", "*_go.publishWithHeader"},
    45  		{"6.6.0", "*_go.publishWithMatrixParams"},
    46  		{"6.6.1", "*_go.publishZipAndModApi"},
    47  		{utils.Development, "*_go.publishZipAndModApi"},
    48  		{"6.10.2", "*_go.publishZipAndModApi"},
    49  	}
    50  	for _, test := range tests {
    51  		t.Run(test.artifactoryVersion, func(t *testing.T) {
    52  			result := GetCompatiblePublisher(test.artifactoryVersion)
    53  			if reflect.TypeOf(result).String() != test.expectedResult {
    54  				t.Error("Expected:", test.expectedResult, "Got:", reflect.TypeOf(result).String())
    55  			}
    56  		})
    57  	}
    58  }