github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/gotest/parse_files_command_test.go (about)

     1  package gotest_test
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/evergreen-ci/evergreen"
     9  	agentutil "github.com/evergreen-ci/evergreen/agent/testutil"
    10  	"github.com/evergreen-ci/evergreen/model"
    11  	"github.com/evergreen-ci/evergreen/model/task"
    12  	. "github.com/evergreen-ci/evergreen/plugin/builtin/gotest"
    13  	"github.com/evergreen-ci/evergreen/testutil"
    14  	"github.com/mongodb/grip/slogger"
    15  	. "github.com/smartystreets/goconvey/convey"
    16  )
    17  
    18  func TestAllOutputFiles(t *testing.T) {
    19  	Convey("When determining the name of all files to be parsed", t, func() {
    20  		cwd := testutil.GetDirectoryOfFile()
    21  
    22  		Convey("All specified files should be included", func() {
    23  
    24  			pfCmd := &ParseFilesCommand{
    25  				Files: []string{
    26  					filepath.Join(cwd, "testdata", "monitor.suite"),
    27  					filepath.Join(cwd, "testdata", "util.suite"),
    28  				},
    29  			}
    30  
    31  			files, err := pfCmd.AllOutputFiles()
    32  			So(err, ShouldBeNil)
    33  			So(len(files), ShouldEqual, 2)
    34  
    35  		})
    36  
    37  		Convey("File patterns should be expanded correctly", func() {
    38  
    39  			pfCmd := &ParseFilesCommand{
    40  				Files: []string{
    41  					filepath.Join(cwd, "testdata", "monitor.suite"),
    42  					filepath.Join(cwd, "testdata", "test_output_dir", "*"),
    43  				},
    44  			}
    45  			files, err := pfCmd.AllOutputFiles()
    46  			So(err, ShouldBeNil)
    47  			So(len(files), ShouldEqual, 4)
    48  
    49  		})
    50  
    51  		Convey("Duplicates should be removed", func() {
    52  
    53  			pfCmd := &ParseFilesCommand{
    54  				Files: []string{
    55  					filepath.Join(cwd, "testdata", "monitor.suite"),
    56  					filepath.Join(cwd, "testdata", "util.suite"),
    57  				},
    58  			}
    59  			files, err := pfCmd.AllOutputFiles()
    60  			So(err, ShouldBeNil)
    61  			So(len(files), ShouldEqual, 2)
    62  
    63  		})
    64  
    65  	})
    66  
    67  }
    68  
    69  func TestParseOutputFiles(t *testing.T) {
    70  
    71  	Convey("When parsing files containing go test output", t, func() {
    72  		cwd := testutil.GetDirectoryOfFile()
    73  
    74  		Convey("The output in all of the specified files should be parsed correctly", func() {
    75  
    76  			// mock up a logger
    77  			logger := agentutil.NewTestLogger(slogger.StdOutAppender())
    78  
    79  			// mock up a task config
    80  			taskConfig := &model.TaskConfig{Task: &task.Task{Id: "taskOne", Execution: 1}}
    81  
    82  			// the files we want to parse
    83  			files := []string{
    84  				filepath.Join(cwd, "testdata", "monitor.suite"),
    85  				filepath.Join(cwd, "testdata", "util.suite"),
    86  				filepath.Join(cwd, "testdata", "test_output_dir", "monitor_fail.suite"),
    87  				filepath.Join(cwd, "testdata", "test_output_dir", "evergreen.suite"),
    88  			}
    89  
    90  			logs, results, err := ParseTestOutputFiles(files, nil, logger, taskConfig)
    91  			So(err, ShouldBeNil)
    92  			So(logs, ShouldNotBeNil)
    93  			So(results, ShouldNotBeNil)
    94  			So(len(results), ShouldEqual, 4)
    95  
    96  		})
    97  
    98  	})
    99  
   100  }
   101  
   102  func TestResultConversion(t *testing.T) {
   103  	Convey("With a set of results", t, func() {
   104  		results := []*TestResult{
   105  			{
   106  				Name:    "TestNothing",
   107  				RunTime: 244 * time.Millisecond,
   108  				Status:  PASS,
   109  			},
   110  			{
   111  				Name:    "TestTwo",
   112  				RunTime: 5000 * time.Millisecond,
   113  				Status:  SKIP,
   114  			},
   115  		}
   116  
   117  		Convey("and their converted form", func() {
   118  			fakeTask := &task.Task{Id: "taskID"}
   119  			newRes := ToModelTestResults(fakeTask, results)
   120  			So(len(newRes.Results), ShouldEqual, len(results))
   121  
   122  			Convey("fields should be transformed correctly", func() {
   123  				So(newRes.Results[0].TestFile, ShouldEqual, results[0].Name)
   124  				So(newRes.Results[0].Status, ShouldEqual, evergreen.TestSucceededStatus)
   125  				So(newRes.Results[0].StartTime, ShouldBeLessThan, newRes.Results[0].EndTime)
   126  				So(newRes.Results[0].EndTime-newRes.Results[0].StartTime,
   127  					ShouldBeBetween, .243, .245) //floating point weirdness
   128  				So(newRes.Results[1].TestFile, ShouldEqual, results[1].Name)
   129  				So(newRes.Results[1].Status, ShouldEqual, evergreen.TestSkippedStatus)
   130  				So(newRes.Results[1].StartTime, ShouldBeLessThan, newRes.Results[1].EndTime)
   131  				So(newRes.Results[1].EndTime-newRes.Results[1].StartTime, ShouldBeBetween, 4.9, 5.1)
   132  			})
   133  		})
   134  	})
   135  }