Skip to content

Commit

Permalink
fix logic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed May 27, 2022
1 parent aa2d092 commit 470e3e1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
6 changes: 3 additions & 3 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
progress.Done()

if toolchain == "custom" {
if !c.Globals.Flag.AutoYes || !c.Globals.Flag.NonInteractive {
if !c.Globals.Flag.AutoYes && !c.Globals.Flag.NonInteractive {
// NOTE: A third-party could share a project with a build command for a
// language that wouldn't normally require one (e.g. Rust), and do evil
// things. So we should notify the user and confirm they would like to
Expand All @@ -193,15 +193,15 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
}
}

if c.Globals.Verbose() && (!c.Globals.Flag.AutoYes || !c.Globals.Flag.NonInteractive) {
if c.Globals.Verbose() && (!c.Globals.Flag.AutoYes && !c.Globals.Flag.NonInteractive) {
text.Break(out)
}

progress = text.ResetProgress(out, c.Globals.Verbose())
progress.Step(fmt.Sprintf("Building package using %s toolchain...", toolchain))

postBuildCallback := func() error {
if !c.Globals.Flag.AutoYes || !c.Globals.Flag.NonInteractive {
if !c.Globals.Flag.AutoYes && !c.Globals.Flag.NonInteractive {
err := promptForBuildContinue(CustomPostBuildScriptMessage, c.Manifest.File.Scripts.PostBuild, out, in, c.Globals.Verbose())
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/compute/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func TestCustomBuild(t *testing.T) {
},
{
name: "avoid prompt confirmation",
args: args("compute build --accept-custom-build --language other"),
args: args("compute build --auto-yes --language other"),
fastlyManifest: `
manifest_version = 2
name = "test"
Expand Down Expand Up @@ -856,7 +856,7 @@ func TestCustomPostBuild(t *testing.T) {
},
{
name: "avoid prompt confirmation",
args: args("compute build --accept-custom-build"),
args: args("compute build --auto-yes"),
applicationConfig: config.File{
Language: config.Language{
Rust: config.Rust{
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
}

loggers = &setup.Loggers{
AcceptDefaults: c.Globals.Flag.AcceptDefaults,
Setup: c.Manifest.File.Setup.Loggers,
Stdout: out,
Setup: c.Manifest.File.Setup.Loggers,
Stdout: out,
}
}

Expand Down Expand Up @@ -558,7 +557,7 @@ func manageNoServiceIDFlow(
manifestFile *manifest.File,
activateTrial activator,
) (serviceID string, serviceVersion *fastly.Version, err error) {
if !globalFlags.AutoYes || !globalFlags.NonInteractive {
if !globalFlags.AutoYes && !globalFlags.NonInteractive {
text.Break(out)
text.Output(out, "There is no Fastly service associated with this package. To connect to an existing service add the Service ID to the fastly.toml file, otherwise follow the prompts to create a service now.")
text.Break(out)
Expand Down
34 changes: 16 additions & 18 deletions pkg/commands/compute/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,10 @@ func TestDeploy(t *testing.T) {
},
},
// The following test validates no prompts are displayed to the user due to
// the use of the --accept-defaults flag.
// the use of the --non-interactive flag.
{
name: "success with setup.backends configuration and accept-defaults",
args: args("compute deploy --accept-defaults --token 123"),
args: args("compute deploy --non-interactive --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
Expand Down Expand Up @@ -740,13 +740,13 @@ func TestDeploy(t *testing.T) {
},
// The following test validates that a new 'originless' backend is created
// when the user has no [setup] configuration and they also pass the
// --accept-defaults flag. This is done by ensuring we DON'T see the
// --non-interactive flag. This is done by ensuring we DON'T see the
// standard 'Creating backend' output because we want to conceal the fact
// that we require a backend for compute services because it's a temporary
// implementation detail.
{
name: "success with no setup.backends configuration and --accept-defaults for new service creation",
args: args("compute deploy --accept-defaults --token 123"),
name: "success with no setup.backends configuration and non-interactive for new service creation",
args: args("compute deploy --non-interactive --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
Expand Down Expand Up @@ -852,10 +852,10 @@ func TestDeploy(t *testing.T) {
},
},
// The following test is the same setup as above, but if the user provides
// the --accept-defaults flag we won't prompt for any backends.
// the --non-interactive flag we won't prompt for any backends.
{
name: "success with no setup.backends configuration and use of --accept-defaults",
args: args("compute deploy --accept-defaults --token 123"),
name: "success with no setup.backends configuration and use of --non-interactive",
args: args("compute deploy --non-interactive --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
Expand Down Expand Up @@ -1012,8 +1012,8 @@ func TestDeploy(t *testing.T) {
},
},
{
name: "success with setup.dictionaries configuration and no existing service and --accept-defaults",
args: args("compute deploy --accept-defaults --token 123"),
name: "success with setup.dictionaries configuration and no existing service and --non-interactive",
args: args("compute deploy --non-interactive --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
Expand Down Expand Up @@ -1218,8 +1218,8 @@ func TestDeploy(t *testing.T) {
},
},
{
name: "success with setup.log_entries configuration and no existing service and --accept-defaults",
args: args("compute deploy --accept-defaults --token 123"),
name: "success with setup.log_entries configuration and no existing service, but a provider defined",
args: args("compute deploy --token 123"),
api: mock.API{
ActivateVersionFn: activateVersionOk,
CreateBackendFn: createBackendOK,
Expand All @@ -1246,16 +1246,14 @@ func TestDeploy(t *testing.T) {
"Y", // when prompted to create a new service
},
wantOutput: []string{
"Uploading package...",
"Activating version...",
"SUCCESS: Deployed package (service 12345, version 1)",
},
dontWantOutput: []string{
"The package code requires the following log endpoints to be created.",
"Name: foo",
"Provider: BigQuery",
"Refer to the help documentation for each provider (if no provider shown, then select your own):",
"fastly logging <provider> create --help",
"Uploading package...",
"Activating version...",
"SUCCESS: Deployed package (service 12345, version 1)",
},
},
} {
Expand All @@ -1268,7 +1266,7 @@ func TestDeploy(t *testing.T) {
if testcase.manifest != "" {
manifestContent = testcase.manifest
}
if err := os.WriteFile(filepath.Join(rootdir, manifest.Filename), []byte(manifestContent), 0777); err != nil {
if err := os.WriteFile(filepath.Join(rootdir, manifest.Filename), []byte(manifestContent), 0o777); err != nil {
t.Fatal(err)
}

Expand Down
37 changes: 17 additions & 20 deletions pkg/commands/compute/setup/loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (
//
// NOTE: It implements the setup.Interface interface.
type Loggers struct {
AcceptDefaults bool
Setup map[string]*manifest.SetupLogger
Stdout io.Writer
Setup map[string]*manifest.SetupLogger
Stdout io.Writer
}

// Logger represents the configuration parameters for creating a dictionary
Expand All @@ -25,26 +24,24 @@ type Logger struct {

// Configure prompts the user for specific values related to the service resource.
func (l *Loggers) Configure() error {
if !l.AcceptDefaults {
text.Break(l.Stdout)
text.Info(l.Stdout, "The package code requires the following log endpoints to be created.")
text.Break(l.Stdout)

for name, settings := range l.Setup {
text.Output(l.Stdout, "%s %s", text.Bold("Name:"), name)
if settings.Provider != "" {
text.Output(l.Stdout, "%s %s", text.Bold("Provider:"), settings.Provider)
}
text.Break(l.Stdout)
text.Break(l.Stdout)
text.Info(l.Stdout, "The package code requires the following log endpoints to be created.")
text.Break(l.Stdout)

for name, settings := range l.Setup {
text.Output(l.Stdout, "%s %s", text.Bold("Name:"), name)
if settings.Provider != "" {
text.Output(l.Stdout, "%s %s", text.Bold("Provider:"), settings.Provider)
}

text.Description(
l.Stdout,
"Refer to the help documentation for each provider (if no provider shown, then select your own)",
"fastly logging <provider> create --help",
)
text.Break(l.Stdout)
}

text.Description(
l.Stdout,
"Refer to the help documentation for each provider (if no provider shown, then select your own)",
"fastly logging <provider> create --help",
)

return nil
}

Expand Down

0 comments on commit 470e3e1

Please sign in to comment.