Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
* Rename trusted-builder to trusted-builders, to follow RFC
* Change Config to NewConfigCommand

Signed-off-by: David Freilich <dfreilich@vmware.com>
  • Loading branch information
dfreilich committed Nov 18, 2020
1 parent b5162dc commit e0d9378
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 93 deletions.
53 changes: 22 additions & 31 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,26 @@ import (
"testing"
"time"

"github.com/buildpacks/pack/internal/style"

pubcfg "github.com/buildpacks/pack/config"

"github.com/ghodss/yaml"
"github.com/pelletier/go-toml"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/ghodss/yaml"
"github.com/google/go-containerregistry/pkg/name"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/pack/acceptance/buildpacks"

"github.com/buildpacks/pack/acceptance/assertions"
"github.com/buildpacks/pack/acceptance/buildpacks"
"github.com/buildpacks/pack/acceptance/config"
"github.com/buildpacks/pack/acceptance/invoke"
pubcfg "github.com/buildpacks/pack/config"
"github.com/buildpacks/pack/internal/archive"
"github.com/buildpacks/pack/internal/cache"
"github.com/buildpacks/pack/internal/style"
h "github.com/buildpacks/pack/testhelpers"
)

Expand Down Expand Up @@ -181,9 +177,9 @@ func testWithoutSpecificBuilderRequirement(
})

when("pack config", func() {
when("trusted-builder", func() {
when("trusted-builders", func() {
it("prints list of trusted builders", func() {
output := pack.RunSuccessfully("config", "trusted-builder")
output := pack.RunSuccessfully("config", "trusted-builders")

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.IncludesTrustedBuildersHeading()
Expand All @@ -197,7 +193,7 @@ func testWithoutSpecificBuilderRequirement(
it("sets the builder as trusted in ~/.pack/config.toml", func() {
builderName := "some-builder" + h.RandString(10)

output := pack.RunSuccessfully("config", "trusted-builder", "add", builderName)
output := pack.RunSuccessfully("config", "trusted-builders", "add", builderName)
assert.NotContains(output, "has been deprecated")
assert.Contains(pack.ConfigFileContents(), builderName)
})
Expand All @@ -207,11 +203,11 @@ func testWithoutSpecificBuilderRequirement(
it("removes the previously trusted builder from ~/${PACK_HOME}/config.toml", func() {
builderName := "some-builder" + h.RandString(10)

pack.JustRunSuccessfully("config", "trusted-builder", "add", builderName)
pack.JustRunSuccessfully("config", "trusted-builders", "add", builderName)

assert.Contains(pack.ConfigFileContents(), builderName)

output := pack.RunSuccessfully("config", "trusted-builder", "remove", builderName)
output := pack.RunSuccessfully("config", "trusted-builders", "remove", builderName)
assert.NotContains(output, "has been deprecated")

assert.NotContains(pack.ConfigFileContents(), builderName)
Expand All @@ -220,7 +216,7 @@ func testWithoutSpecificBuilderRequirement(

when("list", func() {
it("prints list of trusted builders", func() {
output := pack.RunSuccessfully("config", "trusted-builder", "list")
output := pack.RunSuccessfully("config", "trusted-builders", "list")

assertOutput := assertions.NewOutputAssertionManager(t, output)
assertOutput.IncludesTrustedBuildersHeading()
Expand All @@ -230,12 +226,12 @@ func testWithoutSpecificBuilderRequirement(
assert.NotContains(output, "has been deprecated")
})

it("shows a builder trusted by pack config trusted-builder add", func() {
it("shows a builder trusted by pack config trusted-builders add", func() {
builderName := "some-builder" + h.RandString(10)

pack.JustRunSuccessfully("config", "trusted-builder", "add", builderName)
pack.JustRunSuccessfully("config", "trusted-builders", "add", builderName)

output := pack.RunSuccessfully("config", "trusted-builder", "list")
output := pack.RunSuccessfully("config", "trusted-builders", "list")
assert.Contains(output, builderName)
})
})
Expand Down Expand Up @@ -828,21 +824,18 @@ func testAcceptance(
it.Before(func() {
pack.JustRunSuccessfully("set-default-builder", builderName)

var trustBuilder bool
if pack.Supports("config trusted-builder add") {
pack.JustRunSuccessfully("config", "trusted-builder", "add", builderName)
trustBuilder = true
} else if pack.Supports("trust-builder") {
if pack.Supports("config trusted-builders add") {
pack.JustRunSuccessfully("config", "trusted-builders", "add", builderName)
} else {
pack.JustRunSuccessfully("trust-builder", builderName)
trustBuilder = true
}

// Technically the creator is supported as of platform API version 0.3 (lifecycle version 0.7.0+) but earlier versions
// have bugs that make using the creator problematic.
creatorSupported := lifecycle.SupportsFeature(config.CreatorInLifecycle) &&
pack.SupportsFeature(invoke.CreatorInPack)

usingCreator = creatorSupported && trustBuilder
usingCreator = creatorSupported
})

it("creates a runnable, rebuildable image on daemon from app dir", func() {
Expand Down Expand Up @@ -2077,10 +2070,8 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
})

it("indicates builder is trusted", func() {
h.SkipUnless(t, pack.Supports("trust-builder"), "version of pack doesn't trust-builder command")

if pack.Supports("config trusted-builder add") {
pack.JustRunSuccessfully("config", "trusted-builder", "add", builderName)
if pack.Supports("config trusted-builders add") {
pack.JustRunSuccessfully("config", "trusted-builders", "add", builderName)
} else {
pack.JustRunSuccessfully("trust-builder", builderName)
}
Expand Down Expand Up @@ -2126,8 +2117,8 @@ include = [ "*.jar", "media/mountain.jpg", "media/person.png" ]
var buildRunImage func(string, string, string)

it.Before(func() {
if pack.Supports("config trusted-builder add") {
pack.JustRunSuccessfully("config", "trusted-builder", "add", builderName)
if pack.Supports("config trusted-builders add") {
pack.JustRunSuccessfully("config", "trusted-builders", "add", builderName)
} else {
pack.JustRunSuccessfully("trust-builder", builderName)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {

rootCmd.AddCommand(commands.CompletionCommand(logger))

rootCmd.AddCommand(cmdConfig.Config(logger, cfg, cfgPath))
rootCmd.AddCommand(cmdConfig.NewConfigCommand(logger, cfg, cfgPath))
rootCmd.AddCommand(stack.Stack(logger))

rootCmd.Version = pack.Version
Expand Down
5 changes: 2 additions & 3 deletions internal/commands/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package config
import (
"fmt"

"github.com/buildpacks/pack/internal/commands"

"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/logging"
)

func Config(logger logging.Logger, cfg config.Config, cfgPath string) *cobra.Command {
func NewConfigCommand(logger logging.Logger, cfg config.Config, cfgPath string) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Interact with pack config",
Expand Down
16 changes: 6 additions & 10 deletions internal/commands/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"path/filepath"
"testing"

"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/spf13/cobra"

cmdConfig "github.com/buildpacks/pack/internal/commands/config"
"github.com/buildpacks/pack/internal/config"
ilogging "github.com/buildpacks/pack/internal/logging"
"github.com/buildpacks/pack/logging"
h "github.com/buildpacks/pack/testhelpers"

"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
)

func TestConfigCommand(t *testing.T) {
Expand All @@ -41,16 +40,13 @@ func testConfigCommand(t *testing.T, when spec.G, it spec.S) {
logger = ilogging.NewLogWithWriters(&outBuf, &outBuf)
tempPackHome, err = ioutil.TempDir("", "pack-home")
h.AssertNil(t, err)
h.AssertNil(t, os.Setenv("PACK_HOME", tempPackHome))
configPath = filepath.Join(tempPackHome, "config.toml")

command = cmdConfig.Config(logger, config.Config{}, configPath)
command = cmdConfig.NewConfigCommand(logger, config.Config{}, configPath)
command.SetOut(logging.GetWriterForLevel(logger, logging.InfoLevel))
//command.SetErr(logging.GetWriterForLevel(logger, logging.ErrorLevel))
})

it.After(func() {
h.AssertNil(t, os.Unsetenv("PACK_HOME"))
h.AssertNil(t, os.RemoveAll(tempPackHome))
})

Expand All @@ -64,9 +60,9 @@ func testConfigCommand(t *testing.T, when spec.G, it spec.S) {
})
})

when("trusted-builder", func() {
when("trusted-builders", func() {
it("prints list of trusted builders", func() {
command.SetArgs([]string{"trusted-builder"})
command.SetArgs([]string{"trusted-builders"})
h.AssertNil(t, command.Execute())
h.AssertContainsAllInOrder(t,
outBuf,
Expand Down
7 changes: 3 additions & 4 deletions internal/commands/config/list_trusted_builders.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package config

import (
"github.com/buildpacks/pack/internal/commands"

"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/logging"
)

// Deprecated: Use `list` instead
// Deprecated: Use `trusted-builders list` instead
func ListTrustedBuilders(logger logging.Logger, cfg config.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "list-trusted-builders",
Expand All @@ -18,7 +17,7 @@ func ListTrustedBuilders(logger logging.Logger, cfg config.Config) *cobra.Comman
Example: "pack list-trusted-builders",
Hidden: true,
RunE: commands.LogError(logger, func(cmd *cobra.Command, args []string) error {
commands.DeprecationWarning(logger, "list-trusted-builders", "config trusted-builder list")
commands.DeprecationWarning(logger, "list-trusted-builders", "config trusted-builders list")
listTrustedBuilders(logger, cfg)
return nil
}),
Expand Down
6 changes: 2 additions & 4 deletions internal/commands/config/list_trusted_builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import (
"os"
"testing"

cmdConfig "github.com/buildpacks/pack/internal/commands/config"

"github.com/buildpacks/pack/internal/config"

"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/spf13/cobra"

cmdConfig "github.com/buildpacks/pack/internal/commands/config"
"github.com/buildpacks/pack/internal/config"
ilogging "github.com/buildpacks/pack/internal/logging"
"github.com/buildpacks/pack/logging"
h "github.com/buildpacks/pack/testhelpers"
Expand Down
5 changes: 2 additions & 3 deletions internal/commands/config/trust_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/commands"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/logging"
)

// Deprecated: Use `trusted-builder add` instead
// Deprecated: Use `trusted-builders add` instead
func TrustBuilder(logger logging.Logger, cfg config.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "trust-builder <builder-name>",
Expand All @@ -20,7 +19,7 @@ func TrustBuilder(logger logging.Logger, cfg config.Config) *cobra.Command {
Example: "pack trust-builder cnbs/sample-stack-run:bionic",
Hidden: true,
RunE: commands.LogError(logger, func(cmd *cobra.Command, args []string) error {
commands.DeprecationWarning(logger, "trust-builder", "config trusted-builder add")
commands.DeprecationWarning(logger, "trust-builder", "config trusted-builders add")
configPath, err := config.DefaultConfigPath()
if err != nil {
return errors.Wrap(err, "getting config path")
Expand Down
3 changes: 1 addition & 2 deletions internal/commands/config/trust_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"path/filepath"
"testing"

cmdConfig "github.com/buildpacks/pack/internal/commands/config"

"github.com/heroku/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/spf13/cobra"

cmdConfig "github.com/buildpacks/pack/internal/commands/config"
"github.com/buildpacks/pack/internal/config"
ilogging "github.com/buildpacks/pack/internal/logging"
"github.com/buildpacks/pack/logging"
Expand Down
20 changes: 9 additions & 11 deletions internal/commands/config/trusted_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@ import (
"sort"

"github.com/pkg/errors"

"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/style"

"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/commands"
"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/logging"
)

func trustedBuilder(logger logging.Logger, cfg config.Config, cfgPath string) *cobra.Command {
cmd := &cobra.Command{
Use: "trusted-builder",
Use: "trusted-builders",
Short: "Interact with trusted builders",
Aliases: []string{"trusted-builders"},
Aliases: []string{"trusted-builder"},
RunE: commands.LogError(logger, func(cmd *cobra.Command, args []string) error {
listTrustedBuilders(logger, cfg)
return nil
}),
}

addCmd := generateAdd("trusted-builder", logger, cfg, cfgPath, addTrustedBuilder)
addCmd := generateAdd("trusted-builders", logger, cfg, cfgPath, addTrustedBuilder)
addCmd.Long = "Trust builder.\n\nWhen building with this builder, all lifecycle phases will be run in a single container using the builder image."
addCmd.Example = "pack config trusted-builder add cnbs/sample-stack-run:bionic"
addCmd.Example = "pack config trusted-builders add cnbs/sample-stack-run:bionic"
cmd.AddCommand(addCmd)

rmCmd := generateRemove("trusted-builder", logger, cfg, cfgPath, removeTrustedBuilder)
rmCmd := generateRemove("trusted-builders", logger, cfg, cfgPath, removeTrustedBuilder)
rmCmd.Long = "Stop trusting builder.\n\nWhen building with this builder, all lifecycle phases will be no longer be run in a single container using the builder image."
rmCmd.Example = "pack config trusted-builder remove cnbs/sample-stack-run:bionic"
rmCmd.Example = "pack config trusted-builders remove cnbs/sample-stack-run:bionic"
cmd.AddCommand(rmCmd)

listCmd := generateListCmd("trusted-builders", logger, cfg, listTrustedBuilders)
listCmd.Long = "List Trusted Builders.\n\nShow the builders that are either trusted by default or have been explicitly trusted locally using `trust-builder`"
listCmd.Example = "pack config trusted-builder list"
listCmd.Example = "pack config trusted-builders list"
cmd.AddCommand(listCmd)
return cmd
}
Expand Down
Loading

0 comments on commit e0d9378

Please sign in to comment.