-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4423d4
commit 7d9a6c3
Showing
5 changed files
with
517 additions
and
2 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,69 @@ | ||
package commands | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/ms-henglu/armstrong/report" | ||
"github.com/sirupsen/logrus" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
type ApiTestGenerateReportCommand struct { | ||
workingDir string | ||
swaggerPath string | ||
} | ||
|
||
func (c *ApiTestGenerateReportCommand) flags() *flag.FlagSet { | ||
fs := defaultFlagSet("api-test-generate-report") | ||
fs.StringVar(&c.workingDir, "working-dir", "", "path that contains all the test cases") | ||
fs.StringVar(&c.swaggerPath, "swagger", "", "path to the .json swagger which is being test") | ||
fs.Usage = func() { logrus.Error(c.Help()) } | ||
return fs | ||
} | ||
|
||
func (c ApiTestGenerateReportCommand) Help() string { | ||
helpText := ` | ||
Usage: armstrong api-test-generate-report | ||
` + c.Synopsis() + "\n\n" + helpForFlags(c.flags()) | ||
|
||
return strings.TrimSpace(helpText) | ||
} | ||
|
||
func (c ApiTestGenerateReportCommand) Synopsis() string { | ||
return "Generate test report for a set of test results" | ||
} | ||
|
||
func (c ApiTestGenerateReportCommand) Run(args []string) int { | ||
f := c.flags() | ||
if err := f.Parse(args); err != nil { | ||
logrus.Error(fmt.Sprintf("Error parsing command-line flags: %s", err)) | ||
return 1 | ||
} | ||
return c.Execute() | ||
} | ||
|
||
func (c ApiTestGenerateReportCommand) Execute() int { | ||
log.Println("[INFO] ----------- generate API Test Report ---------") | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
logrus.Error(fmt.Sprintf("failed to get working directory: %+v", err)) | ||
return 1 | ||
} | ||
|
||
if c.workingDir != "" { | ||
wd, err = filepath.Abs(c.workingDir) | ||
if err != nil { | ||
logrus.Error(fmt.Sprintf("working directory is invalid: %+v", err)) | ||
return 1 | ||
} | ||
} | ||
|
||
if report.GenerateApiTestReports(wd, c.swaggerPath) != nil { | ||
log.Fatalf("[ERROR] failed to generate API Test Report: %+v", err) | ||
} | ||
|
||
return 0 | ||
} |
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
Oops, something went wrong.