github.com/grahambrereton-form3/tilt@v0.10.18/internal/token/token_test.go (about)

     1  package token
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"github.com/windmilleng/wmclient/pkg/dirs"
     8  
     9  	"github.com/windmilleng/tilt/internal/testutils/tempdir"
    10  )
    11  
    12  func TestGetOrCreateToken(t *testing.T) {
    13  	f := newFixture(t)
    14  	t1, err := GetOrCreateToken(f.dir)
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	t2, err := GetOrCreateToken(f.dir)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	// The token returned in the second GetOrCreateToken call should be the same as the one
    23  	// that was created in the first call.
    24  	// This test thus demonstrates both that a token is created if it doesn't exist
    25  	// and that a token can be read if it does exist
    26  	require.Equal(f.t, t1, t2)
    27  }
    28  
    29  type fixture struct {
    30  	*tempdir.TempDirFixture
    31  	t   *testing.T
    32  	dir *dirs.WindmillDir
    33  }
    34  
    35  func newFixture(t *testing.T) *fixture {
    36  	f := tempdir.NewTempDirFixture(t)
    37  	temp := dirs.NewWindmillDirAt(f.Path())
    38  	return &fixture{
    39  		TempDirFixture: f,
    40  		t:              t,
    41  		dir:            temp,
    42  	}
    43  }