github.com/creativeprojects/go-selfupdate@v1.2.0/cmd/source_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestSplitDomainSlug(t *testing.T) {
    10  	fixtures := []struct {
    11  		repo    string
    12  		domain  string
    13  		slug    string
    14  		isValid bool
    15  	}{
    16  		{"owner/name", "", "owner/name", true},
    17  		{"owner/name/", "", "", false},
    18  		{"/owner/name", "", "", false},
    19  		{"github.com/owner/name", "https://github.com", "owner/name", true},
    20  		{"http://github.com/owner/name", "http://github.com", "owner/name", true},
    21  		{"http://github.com", "", "", false},
    22  		{"http://github.com/", "", "", false},
    23  		{"https://github.com/", "", "", false},
    24  		{"github.com/", "", "", false},
    25  		{"github.com", "", "", false},
    26  	}
    27  
    28  	for _, fixture := range fixtures {
    29  		t.Run(fixture.repo, func(t *testing.T) {
    30  			domain, slug, err := SplitDomainSlug(fixture.repo)
    31  			assert.Equal(t, fixture.domain, domain)
    32  			assert.Equal(t, fixture.slug, slug)
    33  			if fixture.isValid {
    34  				assert.NoError(t, err)
    35  			} else {
    36  				assert.Error(t, err)
    37  				t.Log(err)
    38  			}
    39  		})
    40  	}
    41  }