// RunTests runs extension tests when invoked from Gohan CLI func RunTests(c *cli.Context) { setUpLogging() testFiles := getTestFiles(c.Args()) summary := map[string]error{} for _, testFile := range testFiles { log.Info("Running tests from '%s':", testFile) testRunner := runner.NewTestRunner(testFile) errors := testRunner.Run() if err, ok := errors[runner.GeneralError]; ok { summary[testFile] = fmt.Errorf("%s", err.Error()) log.Error(fmt.Sprintf("Error: %s", err.Error())) continue } failed := 0 for test, err := range errors { if err != nil { failed = failed + 1 log.Error(fmt.Sprintf("\t FAIL (%s): %s", test, err.Error())) } else if c.Bool("verbose") { log.Notice("\t PASS (%s)", test) } } summary[testFile] = nil if failed > 0 { summary[testFile] = fmt.Errorf("%d/%d tests failed", failed, len(errors)) } } returnCode := 0 log.Info("Run %d test files:", len(summary)) for testFile, err := range summary { if err != nil { returnCode = 1 log.Error(fmt.Sprintf("Failure in %s: %s", testFile, err.Error())) } else { log.Notice("OK %s ", testFile) } } os.Exit(returnCode) }
// RunTests runs extension tests for CLI func RunTests(testFiles []string, printAllLogs bool) (returnCode int) { errors := map[string]map[string]error{} for _, testFile := range testFiles { testRunner := runner.NewTestRunner(testFile, printAllLogs) errors[testFile] = testRunner.Run() if err, ok := errors[testFile][runner.GeneralError]; ok { log.Error(fmt.Sprintf("\t ERROR (%s): %v", testFile, err)) } } summary := makeSummary(errors) printSummary(summary, printAllLogs) for _, err := range summary { if err != nil { return 1 } } return 0 }
var _ = Describe("Runner", func() { const ( schemaIncludesVar = "SCHEMA_INCLUDES" schemasVar = "SCHEMAS" pathVar = "PATH" ) var ( testFile string testFilter string errors map[string]error ) JustBeforeEach(func() { theRunner := runner.NewTestRunner(testFile, true, testFilter) errors = theRunner.Run() }) AfterEach(func() { testFilter = "" }) Describe("With incorrect files", func() { Context("When the file does not exist", func() { BeforeEach(func() { testFile = "./test_data/nonexising_file.js" }) It("Should return the proper errors", func() { Expect(errors).To(HaveLen(1))
. "github.com/onsi/gomega" ) var _ = Describe("Runner", func() { const ( schemasVar = "SCHEMAS" pathVar = "PATH" ) var ( testFile string errors map[string]error ) JustBeforeEach(func() { theRunner := runner.NewTestRunner(testFile) errors = theRunner.Run() }) Describe("With incorrect files", func() { Context("When the file does not exist", func() { BeforeEach(func() { testFile = "./test_data/nonexising_file.js" }) It("Should return the proper errors", func() { Expect(errors).To(HaveLen(1)) Expect(errors).To(HaveKeyWithValue(runner.GeneralError, MatchError(ContainSubstring("no such file")))) }) })