Skip to content

Commit

Permalink
fix: coverage, failures, and doc fixes (#24)
Browse files Browse the repository at this point in the history
* fix: added failure test coverage

* fix: added docs and updated to include description field

* fix: updated breakpoints and TOC for HTML report

* fix: updated links to carousel in docs and regenerated

* fix: lint fixed
  • Loading branch information
madhuravius authored Jul 23, 2022
1 parent 14d2dbc commit d75e274
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 105 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ build:
.PHONY: build

docs:
go run *.go run \
-i ./cmd/test_data/01_basic_flow_will_pass.yaml \
-o ./docs/example-outputs/carousel \
-r carousel \
-u False
go run *.go run \
-i ./cmd/test_data/01_basic_flow_will_pass.yaml \
-o ./docs/example-outputs/html-simple \
Expand Down
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// templateFile - yaml formatted
const templateFile = `label: clingy flow
description: sample description
steps:
- label: start
description: starting clingy flow
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func RootCmd(c *RootConfig) *cobra.Command {
rootCmd.PersistentFlags().BoolVarP(&unixTimestampDirDisabled, "unixTimestampDirDisabled", "u", false, "disable saving output by unix timestamp subdirectories to output directory")
rootCmd.PersistentFlags().StringVarP(&outputPath, "outputPath", "o", outputPath, "build path that dumps outputs")
rootCmd.PersistentFlags().StringVarP(&inputFile, "inputFile", "i", inputFile, "input file representing a .clingy.yaml")
rootCmd.PersistentFlags().StringVarP(&reportStyle, "reportStyle", "r", reportStyle, "report style to output to (choices: 'html-simple', 'images-only')")
rootCmd.PersistentFlags().StringVarP(&reportStyle, "reportStyle", "r", reportStyle, "report style to output to (choices: 'carousel', 'html-simple', 'images-only')")
rootCmd.Flags().SortFlags = true

return rootCmd
Expand Down
16 changes: 8 additions & 8 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func (r *RootConfig) newRunCmd() *cobra.Command {

if err := lib.ClingyCanRun(); err != nil {
logger.Println("Unable to run clingy due to error in startup", err)
fmt.Printf("Clingy cannot run for reason: %s\n", err.Error())
cmd.Printf("Clingy cannot run for reason: %s\n", err.Error())
r.ExitTools.Exit(1)
}

clingyData, err := lib.ParseClingyFile(logger, inputFile)
if err != nil {
fmt.Printf("Error in reading: %s %s\n", inputFile, err.Error())
cmd.Printf("Error in reading: %s %s\n", inputFile, err.Error())
r.ExitTools.Exit(1)
}
fmt.Printf("Running: %s", clingyData.Label)
cmd.Printf("Running: %s", clingyData.Label)

for idx, step := range clingyData.Steps {
// clear terminal for fresh screenshot
Expand Down Expand Up @@ -78,7 +78,7 @@ func (r *RootConfig) newRunCmd() *cobra.Command {

// if output key, process output and store it for future use
if step.OutputProcessing != nil {
fmt.Printf("Output processing found for key %s\n", step.OutputProcessing.Key)
cmd.Printf("Output processing found for key %s\n", step.OutputProcessing.Key)
if err := lib.HydrateOutput(logger, string(output), clingyData, idx); err != nil {
cmd.Println("Error in capturing output in processing", err)
r.ExitTools.Exit(1)
Expand All @@ -90,16 +90,16 @@ func (r *RootConfig) newRunCmd() *cobra.Command {
internal.ClearTerminal()
switch reportStyle {
case "images-only":
fmt.Printf("Completed clingy run, generated images at %s.", getOutputPath())
case "html-simple":
cmd.Printf("Completed clingy run, generated images at %s.\n", getOutputPath())
case "carousel", "html-simple":
cmd.Println("Completed clingy run, generating report.")

reportPath := fmt.Sprintf("%s/index.html", getOutputPath())
if err := internal.GenerateHTMLReport(logger, clingyData, reportPath); err != nil {
if err := internal.GenerateHTMLReport(logger, clingyData, reportStyle, reportPath); err != nil {
cmd.Println("Error in generating report")
r.ExitTools.Exit(1)
}
fmt.Printf("Generated report: %s\n", reportPath)
cmd.Printf("Generated report: %s\n", reportPath)
}
},
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -30,6 +32,30 @@ func TestRunCmdExecuteSuccess(t *testing.T) {
}
}

func TestRunCmdExecuteFailures(t *testing.T) {
mockTools := internal.GenerateMockInterfacesForClingy(t)
defer mockTools.Ctrl.Finish()

mockTools.MagickClientImpl.EXPECT().CaptureWindow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
files, err := os.ReadDir("./test_data")
if err != nil {
t.Fatalf("Error in reading test_data directory's files %s", err.Error())
}
for _, file := range files {
if strings.Contains(file.Name(), "will_fail") {
mockTools.ExitClientsImpl.EXPECT().Exit(1) // this is important, make sure we expect a failure
b := new(bytes.Buffer)
cmd := RootCmd(&RootConfig{ExitTools: mockTools.ExitClientsImpl, ImageTools: mockTools.MagickClientImpl})
cmd.SetOut(b)
cmd.SetErr(b)
cmd.SetArgs([]string{"run", "-o", "../output", "-i", fmt.Sprintf("./test_data/%s", file.Name())})
_ = cmd.Execute()
out, _ := ioutil.ReadAll(b)
assert.Contains(t, string(out), "Error ")
}
}
}

func TestRunCmdHelpSuccess(t *testing.T) {
mockTools := internal.GenerateMockInterfacesForClingy(t)
defer mockTools.Ctrl.Finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
label: "will fail - no steps"
description: sample description
steps:
1 change: 1 addition & 0 deletions cmd/test_data/01_basic_flow_will_pass.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
description: starting the example flow
Expand Down
1 change: 1 addition & 0 deletions cmd/test_data/02_basic_full_input_will_pass.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
1 change: 1 addition & 0 deletions cmd/test_data/03_basic_full_input_overwrite_will_pass.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
1 change: 1 addition & 0 deletions cmd/test_data/04_basic_regex_input_will_pass.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
1 change: 1 addition & 0 deletions cmd/test_data/06_basic_positional_input_will_pass.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
Expand Down
17 changes: 17 additions & 0 deletions cmd/test_data/08_basic_regex_input_will_fail_no_match.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
args:
- Starting
- label: saving input
command: echo
args:
- "unmatched-input-value"
output_processing:
key: sample_input_key
matching_args:
regex: \[\[([^]]+)\]
matching_type: regex
fail_on_no_match: true
18 changes: 18 additions & 0 deletions cmd/test_data/09_basic_positional_input_will_fail_no_match.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
label: "basic flow #1"
description: sample description
steps:
- label: start
command: echo
args:
- Starting
- label: saving input
command: echo
args:
- "unmatched-input-value"
output_processing:
key: sample_input_key
matching_args:
positional_delimiter: "-"
positional_index: 3
matching_type: positional
fail_on_no_match: true
7 changes: 7 additions & 0 deletions docs/02_yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ By default, `clingy init` will place a `.clingy.yaml` file in your present worki
* `label` - a label to label the entire clingy workflow
* `description` - provide a description for the clingy workflow

```yaml
label: sample label
description: sample description
```
Gets set on the top level with the above, like [this example](/clingy/example-outputs/html-simple).
## Environment variables
If you have environment variables you wish to pass into the YAML, you can do so with the following
Expand Down
2 changes: 1 addition & 1 deletion docs/03_outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This generates a simple HTML report that includes:

## HTML Reports - Carousel

Example can be found at this link [here](/).
Example can be found at this link [here](/clingy/example-outputs/carousel).

This generates a simple HTML report that includes:

Expand Down
Binary file added docs/example-outputs/carousel/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/example-outputs/carousel/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/example-outputs/carousel/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/example-outputs/carousel/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions docs/example-outputs/carousel/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<html lang="en" data-theme="dark">
<head>
<title>Clingy Report - basic flow #1</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-grid.min.css">
<style>
html {
overflow-x: hidden;
}
main.container {
overflow: hidden;
}
img.baseImage {
max-height: 70vh;
}
</style>
</head>
<body>
<main class="container">
<div class="row">
<div class="col-sm-7 offset-sm-1">
<hgroup>
<h1>
basic flow #1
</h1>
<h2>

sample description

</h2>
</hgroup>
</div>
<div class="col-sm-4">
<a href="#" class="contrast outline prev" role="button">Prev</a>
<a href="#" class="contrast outline next" role="button">Next</a>
</div>
</div>
<div class="row">
<div class="siema col-sm-11 offset-sm-1">

<div class="slide">
<hgroup>
<h3 id="0">
#0 start
</h3>
<h4>
starting the example flow
</h4>
</hgroup>
<img class="baseImage" alt="screenshot of start" src="0.jpg" />
</div>

<div class="slide">
<hgroup>
<h3 id="1">
#1 waiting
</h3>
<h4>
sleeping for 1 second
</h4>
</hgroup>
<img class="baseImage" alt="screenshot of waiting" src="1.jpg" />
</div>

<div class="slide">
<hgroup>
<h3 id="2">
#2 printing timestamp
</h3>
<h4>
printing the date
</h4>
</hgroup>
<img class="baseImage" alt="screenshot of printing timestamp" src="2.jpg" />
</div>

<div class="slide">
<hgroup>
<h3 id="3">
#3 finish
</h3>
<h4>
finishing the example flow
</h4>
</hgroup>
<img class="baseImage" alt="screenshot of finish" src="3.jpg" />
</div>

</div>
</div>
</main>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/siema.min.js" integrity="sha256-o/z6kPkEdOiAuBTgTdUaFN/F+srDaF3EbsJbkeAboXk=" crossorigin="anonymous"></script>
<script>
const siema = new Siema();
document.querySelector('.prev').addEventListener('click', () => siema.prev());
document.querySelector('.next').addEventListener('click', () => siema.next());
</script>
</html>
Binary file modified docs/example-outputs/html-simple/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example-outputs/html-simple/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example-outputs/html-simple/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example-outputs/html-simple/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d75e274

Please sign in to comment.