-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add test cases for
pack config prune-interval
Signed-off-by: Parthiba-Hazra <[email protected]>
- Loading branch information
1 parent
c7cb28e
commit ed9e77e
Showing
7 changed files
with
120 additions
and
18 deletions.
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
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,106 @@ | ||
package commands_test | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/buildpacks/pack/internal/commands" | ||
"github.com/buildpacks/pack/internal/config" | ||
"github.com/buildpacks/pack/pkg/logging" | ||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
func TestConfigPruneInterval(t *testing.T) { | ||
spec.Run(t, "ConfigPruneIntervalCommand", testConfigPruneIntervalCommand, spec.Random(), spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testConfigPruneIntervalCommand(t *testing.T, when spec.G, it spec.S) { | ||
var ( | ||
command *cobra.Command | ||
logger logging.Logger | ||
outBuf bytes.Buffer | ||
tempPackHome string | ||
configFile string | ||
assert = h.NewAssertionManager(t) | ||
cfg = config.Config{} | ||
) | ||
|
||
it.Before(func() { | ||
logger = logging.NewLogWithWriters(&outBuf, &outBuf) | ||
tempPackHome, _ = os.MkdirTemp("", "pack-home") | ||
configFile = filepath.Join(tempPackHome, "config.toml") | ||
|
||
command = commands.ConfigPruneInterval(logger, cfg, configFile) | ||
}) | ||
|
||
it.After(func() { | ||
_ = os.RemoveAll(tempPackHome) | ||
}) | ||
|
||
when("#ConfigPruneInterval", func() { | ||
when("no arguments are provided", func() { | ||
it("lists the current pruning interval", func() { | ||
command.SetArgs([]string{}) | ||
|
||
err := command.Execute() | ||
|
||
assert.Nil(err) | ||
assert.Contains(outBuf.String(), "The current prune interval is") | ||
}) | ||
}) | ||
|
||
when("an argument is provided", func() { | ||
when("argument is valid", func() { | ||
it("sets the provided interval as the pruning interval", func() { | ||
interval := "5d" | ||
command.SetArgs([]string{interval}) | ||
|
||
err := command.Execute() | ||
|
||
assert.Nil(err) | ||
assert.Contains(outBuf.String(), "Successfully set") | ||
}) | ||
}) | ||
|
||
when("argument is invalid", func() { | ||
it("returns an error", func() { | ||
interval := "invalid" | ||
command.SetArgs([]string{interval}) | ||
|
||
err := command.Execute() | ||
|
||
assert.Error(err) | ||
assert.Contains(err.Error(), "invalid interval format") | ||
}) | ||
}) | ||
}) | ||
|
||
when("--unset flag is provided", func() { | ||
it("unsets the pruning interval", func() { | ||
command.SetArgs([]string{"--unset"}) | ||
|
||
err := command.Execute() | ||
|
||
assert.Nil(err) | ||
assert.Contains(outBuf.String(), "Successfully unset pruning interval") | ||
}) | ||
}) | ||
|
||
when("both interval and --unset flag are provided", func() { | ||
it("returns an error", func() { | ||
command.SetArgs([]string{"5d", "--unset"}) | ||
|
||
err := command.Execute() | ||
|
||
assert.Error(err) | ||
assert.Contains(err.Error(), "prune interval and --unset cannot be specified simultaneously") | ||
}) | ||
}) | ||
}) | ||
} |
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
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