get.porter.sh/porter@v1.3.0/pkg/porter/porter_test.go (about)

     1  package porter
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"get.porter.sh/porter/pkg/build/buildkit"
     8  	"get.porter.sh/porter/pkg/config"
     9  	"get.porter.sh/porter/tests"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestPorter_GetBuilder(t *testing.T) {
    14  	// Now that docker is deprecated, always use buildkit for now
    15  	// I didn't remove the config capabilities in case we need it later
    16  
    17  	t.Run("docker deprecated, use buildkit", func(t *testing.T) {
    18  		p := Porter{Config: &config.Config{}}
    19  		p.Data.BuildDriver = config.BuildDriverDocker
    20  		driver := p.GetBuilder(context.Background())
    21  		assert.IsType(t, &buildkit.Builder{}, driver)
    22  	})
    23  	t.Run("buildkit", func(t *testing.T) {
    24  		p := Porter{Config: &config.Config{}}
    25  		p.Data.BuildDriver = config.BuildDriverBuildkit
    26  		driver := p.GetBuilder(context.Background())
    27  		assert.IsType(t, &buildkit.Builder{}, driver)
    28  	})
    29  	t.Run("unspecified", func(t *testing.T) {
    30  		// Always default to Docker
    31  		p := Porter{Config: &config.Config{}}
    32  		p.Data.BuildDriver = ""
    33  		driver := p.GetBuilder(context.Background())
    34  		assert.IsType(t, &buildkit.Builder{}, driver)
    35  	})
    36  }
    37  
    38  func TestPorter_LoadWithSecretResolveError(t *testing.T) {
    39  	ctx := context.Background()
    40  	p := NewTestPorter(t)
    41  
    42  	// Use a config file that has a secret, we aren't setting the secret value so resolve will fail
    43  	p.TestConfig.TestContext.AddTestFileFromRoot("tests/testdata/config/config-with-storage-secret.yaml", "/home/myuser/.porter/config.yaml")
    44  
    45  	// Configure porter to read the config file
    46  	p.TestConfig.DataLoader = config.LoadFromEnvironment()
    47  
    48  	_, err := p.Connect(ctx)
    49  
    50  	// Validate the porter is handling the error
    51  	tests.RequireErrorContains(t, err, "secret not found")
    52  }