github.com/devster/tarreleaser@v0.0.0-20221207180803-c608f4eb8918/pkg/context/context_test.go (about)

     1  package context
     2  
     3  import (
     4  	"github.com/devster/tarreleaser/pkg/config"
     5  	"github.com/stretchr/testify/assert"
     6  	"os"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  func TestNewWithTimeout(t *testing.T) {
    12  	assert.NoError(t, os.Setenv("FOO", "BAR"))
    13  	ctx, cancel := NewWithTimeout(config.Project{}, time.Second)
    14  	assert.NotEmpty(t, ctx.Date)
    15  	assert.Equal(t, "BAR", ctx.Env["FOO"])
    16  
    17  	cancel()
    18  	<-ctx.Done()
    19  	assert.EqualError(t, ctx.Err(), `context canceled`)
    20  }