Skip to content

Commit

Permalink
Fix GetBuilder
Browse files Browse the repository at this point in the history
I accidentally tried to use a fallthrough, which go doesn't support. I
have fixed GetBuilder and added a unit test to validate that it is
creating a build driver for all cases.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs committed Nov 18, 2021
1 parent be0aa83 commit f137e59
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/porter/porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (p *Porter) GetBuilder() build.Builder {
switch p.GetBuildDriver() {
case config.BuildDriverBuildkit:
p.builder = buildkit.NewBuilder(p.Context)
case config.BuildDriverDocker:
default:
p.builder = docker.NewBuilder(p.Context)
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/porter/porter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package porter

import (
"testing"

"get.porter.sh/porter/pkg/build/buildkit"
"get.porter.sh/porter/pkg/build/docker"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/experimental"
"github.com/stretchr/testify/assert"
)

func TestPorter_GetBuilder(t *testing.T) {
t.Run("docker", func(t *testing.T) {
p := Porter{Config: &config.Config{}}
p.SetExperimentalFlags(experimental.FlagBuildDrivers)
p.Data.BuildDriver = config.BuildDriverDocker
driver := p.GetBuilder()
assert.IsType(t, &docker.Builder{}, driver)
})
t.Run("buildkit", func(t *testing.T) {
p := Porter{Config: &config.Config{}}
p.SetExperimentalFlags(experimental.FlagBuildDrivers)
p.Data.BuildDriver = config.BuildDriverBuildkit
driver := p.GetBuilder()
assert.IsType(t, &buildkit.Builder{}, driver)
})
t.Run("unspecified", func(t *testing.T) {
// Always default to Docker
p := Porter{Config: &config.Config{}}
p.SetExperimentalFlags(experimental.FlagBuildDrivers)
p.Data.BuildDriver = ""
driver := p.GetBuilder()
assert.IsType(t, &docker.Builder{}, driver)
})
t.Run("buildkit - experimental flag disabled", func(t *testing.T) {
// Default to docker when the experimental flag isn't set
p := Porter{Config: &config.Config{}}
p.Data.BuildDriver = "buildkit"
driver := p.GetBuilder()
assert.IsType(t, &docker.Builder{}, driver)
})
}

0 comments on commit f137e59

Please sign in to comment.