-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} |