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

     1  package selfupdate
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestInvalidSlug(t *testing.T) {
    10  	for _, slug := range []string{
    11  		"foo",
    12  		"/",
    13  		"foo/",
    14  		"/bar",
    15  		"foo/bar/piyo",
    16  	} {
    17  		t.Run(slug, func(t *testing.T) {
    18  			repo := ParseSlug(slug)
    19  
    20  			_, _, err := repo.GetSlug()
    21  			assert.Error(t, err)
    22  
    23  			_, err = repo.Get()
    24  			assert.Error(t, err)
    25  		})
    26  	}
    27  }
    28  
    29  func TestParseSlug(t *testing.T) {
    30  	slug := ParseSlug("foo/bar")
    31  
    32  	owner, repo, err := slug.GetSlug()
    33  	assert.NoError(t, err)
    34  	assert.Equal(t, "foo", owner)
    35  	assert.Equal(t, "bar", repo)
    36  
    37  	name, err := slug.Get()
    38  	assert.NoError(t, err)
    39  	assert.Equal(t, "foo/bar", name)
    40  }
    41  
    42  func TestNewRepositorySlug(t *testing.T) {
    43  	slug := NewRepositorySlug("foo", "bar")
    44  
    45  	owner, repo, err := slug.GetSlug()
    46  	assert.NoError(t, err)
    47  	assert.Equal(t, "foo", owner)
    48  	assert.Equal(t, "bar", repo)
    49  
    50  	name, err := slug.Get()
    51  	assert.NoError(t, err)
    52  	assert.Equal(t, "foo/bar", name)
    53  }