-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [wip] prototype to support yaml file as input for synthetics mo…
…nitor run command
- Loading branch information
1 parent
5238b16
commit 13a4900
Showing
6 changed files
with
151 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package synthetics | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/newrelic/newrelic-cli/internal/client" | ||
"github.com/newrelic/newrelic-cli/internal/utils" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type commandInputs struct { | ||
Flags map[string]interface{} `yaml:"flags"` | ||
} | ||
|
||
var cmdMonitorRun = &cobra.Command{ | ||
Use: "run", | ||
Short: "Run a synthetics monitor check.", | ||
Long: `Run a synthetics monitor check. | ||
The get command queues a manual request to execute a monitor check from the specified location. | ||
`, | ||
Example: `newrelic synthetics monitor run --guid "<monitorGUID>" --location="<locationId>"`, | ||
PreRun: client.RequireClient, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
// TODO | ||
// If command flags are provided inline as well as an input file for flags, | ||
// the inline flags will take precendence and the input file flags will be ignored. | ||
// Provide a warning message, but return nil and continue command execution in Run(). | ||
|
||
if syntheticsMonitorGUID != "" || syntheticsMonitorLocationID != "" { | ||
return nil | ||
} | ||
|
||
inputFile, err := ioutil.ReadFile(syntheticsMonitorRunFlagsInputFile) | ||
if err != nil { | ||
return fmt.Errorf("YAML err %+v ", err) | ||
} | ||
|
||
cmdInputs := commandInputs{} | ||
err = yaml.Unmarshal(inputFile, &cmdInputs) | ||
if err != nil { | ||
err = json.Unmarshal(inputFile, &cmdInputs) | ||
if err != nil { | ||
return fmt.Errorf("error parsing input file %+v ", err) | ||
} | ||
} | ||
|
||
err = utils.SetFlagsFromFile(cmd, cmdInputs.Flags) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
RunE: execCmdMonitorRunE, | ||
} | ||
|
||
func execCmdMonitorRunE(cmd *cobra.Command, args []string) error { | ||
// TODO: Wire up the client | ||
return nil | ||
} |
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,19 @@ | ||
package synthetics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCmdSyntheticsMonitorRun(t *testing.T) { | ||
cmd := &cobra.Command{ | ||
Use: cmdMonitorRun.Use, | ||
RunE: execCmdMonitorRunE, | ||
} | ||
|
||
err := cmd.Execute() | ||
|
||
assert.NoError(t, err) | ||
} |
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,19 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCmdDo(t *testing.T) { | ||
cmd := &cobra.Command{ | ||
Use: cmdDo.Use, | ||
RunE: runDoCommandE, | ||
} | ||
|
||
err := cmd.Execute() | ||
|
||
assert.NoError(t, err) | ||
} |
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