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

     1  package selfupdate
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCanUseTokenForDomain(t *testing.T) {
    10  	fixtures := []struct {
    11  		origin, other string
    12  		valid         bool
    13  	}{
    14  		{"http://gitlab.com", "http://gitlab.com", true},
    15  		{"http://gitlab.com/owner/repo", "http://gitlab.com/file", true},
    16  		{"http://gitlab.com/owner/repo", "http://download.gitlab.com/file", true},
    17  		{"http://api.gitlab.com", "http://gitlab.com", false},
    18  		{"http://api.gitlab.com/owner/repo", "http://gitlab.com/file", false},
    19  		{"", "http://gitlab.com/file", false},
    20  	}
    21  
    22  	for _, fixture := range fixtures {
    23  		t.Run("", func(t *testing.T) {
    24  			ok, err := canUseTokenForDomain(fixture.origin, fixture.other)
    25  			assert.NoError(t, err)
    26  			assert.Equal(t, fixture.valid, ok)
    27  		})
    28  	}
    29  }