github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/matrix_smoke_test.go (about)

     1  package model
     2  
     3  import (
     4  	"io/ioutil"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/evergreen-ci/evergreen/testutil"
     9  	. "github.com/smartystreets/goconvey/convey"
    10  )
    11  
    12  // findMatrixVariant returns the variant representing a matrix value.
    13  func findMatrixVariant(bvs []BuildVariant, cell matrixValue) *BuildVariant {
    14  	for i, v := range bvs {
    15  		found := 0
    16  		for key, val := range cell {
    17  			if x, ok := v.Expansions[key]; ok && x == val {
    18  				found++
    19  			}
    20  		}
    21  		if found == len(cell) {
    22  			return &bvs[i]
    23  		}
    24  	}
    25  	return nil
    26  }
    27  
    28  // findRegularVariant returns a non-matrix variant of the given id.
    29  func findRegularVariant(bvs []BuildVariant, id string) *BuildVariant {
    30  	for _, v := range bvs {
    31  		if v.Name == id {
    32  			return &v
    33  		}
    34  	}
    35  	return nil
    36  }
    37  
    38  // taskNames returns list of task names give a variant definition.
    39  func taskNames(v *BuildVariant) []string {
    40  	var names []string
    41  	for _, t := range v.Tasks {
    42  		names = append(names, t.Name)
    43  	}
    44  	return names
    45  }
    46  
    47  func TestPythonMatrixIntegration(t *testing.T) {
    48  	Convey("With a sample matrix project mocking up a python driver", t, func() {
    49  		p := Project{}
    50  		bytes, err := ioutil.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(),
    51  			"testdata", "matrix_python.yml"))
    52  		So(err, ShouldBeNil)
    53  		Convey("the project should parse properly", func() {
    54  			err := LoadProjectInto(bytes, "python", &p)
    55  			So(err, ShouldBeNil)
    56  			Convey("and contain the correct variants", func() {
    57  				So(len(p.BuildVariants), ShouldEqual, (2*2*4 - 4))
    58  				Convey("so that excluded matrix cells are not created", func() {
    59  					So(findMatrixVariant(p.BuildVariants, matrixValue{
    60  						"os": "windows", "python": "pypy", "c-extensions": "with-c",
    61  					}), ShouldBeNil)
    62  					So(findMatrixVariant(p.BuildVariants, matrixValue{
    63  						"os": "windows", "python": "jython", "c-extensions": "with-c",
    64  					}), ShouldBeNil)
    65  					So(findMatrixVariant(p.BuildVariants, matrixValue{
    66  						"os": "linux", "python": "pypy", "c-extensions": "with-c",
    67  					}), ShouldBeNil)
    68  					So(findMatrixVariant(p.BuildVariants, matrixValue{
    69  						"os": "linux", "python": "jython", "c-extensions": "with-c",
    70  					}), ShouldBeNil)
    71  				})
    72  				Convey("so that Windows builds without C extensions exclude LDAP tasks", func() {
    73  					v := findMatrixVariant(p.BuildVariants, matrixValue{
    74  						"os":           "windows",
    75  						"python":       "python3",
    76  						"c-extensions": "without-c",
    77  					})
    78  					So(v, ShouldNotBeNil)
    79  					tasks := taskNames(v)
    80  					So(len(tasks), ShouldEqual, 7)
    81  					So(tasks, ShouldNotContain, "ldap_auth")
    82  					So(v.DisplayName, ShouldEqual, "Windows 95 Python 3.0 (without C extensions)")
    83  					So(v.RunOn, ShouldResemble, []string{"windows95-test"})
    84  				})
    85  				Convey("so that the linux/python3/c variant has a lint task", func() {
    86  					v := findMatrixVariant(p.BuildVariants, matrixValue{
    87  						"os":           "linux",
    88  						"python":       "python3",
    89  						"c-extensions": "with-c",
    90  					})
    91  					So(v, ShouldNotBeNil)
    92  					tasks := taskNames(v)
    93  					So(len(tasks), ShouldEqual, 9)
    94  					So(tasks, ShouldContain, "ldap_auth")
    95  					So(tasks, ShouldContain, "lint")
    96  					So(v.DisplayName, ShouldEqual, "Linux Python 3.0 (with C extensions)")
    97  					So(v.RunOn, ShouldResemble, []string{"centos6-perf"})
    98  				})
    99  			})
   100  		})
   101  	})
   102  }
   103  
   104  func TestDepsMatrixIntegration(t *testing.T) {
   105  	Convey("With a sample matrix project mocking up a python driver", t, func() {
   106  		p := Project{}
   107  		bytes, err := ioutil.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(),
   108  			"testdata", "matrix_deps.yml"))
   109  		So(err, ShouldBeNil)
   110  		Convey("the project should parse properly", func() {
   111  			err := LoadProjectInto(bytes, "deps", &p)
   112  			So(err, ShouldBeNil)
   113  			Convey("and contain the correct variants", func() {
   114  				So(len(p.BuildVariants), ShouldEqual, (1 + 3*3))
   115  				Convey("including a non-matrix variant", func() {
   116  					v := findRegularVariant(p.BuildVariants, "analysis")
   117  					So(v, ShouldNotBeNil)
   118  					ts := taskNames(v)
   119  					So(ts, ShouldContain, "pre-task")
   120  					So(ts, ShouldContain, "post-task")
   121  					So(*v.Stepback, ShouldBeFalse)
   122  				})
   123  				Convey("including linux/standalone", func() {
   124  					v := findMatrixVariant(p.BuildVariants, matrixValue{
   125  						"os":            "linux",
   126  						"configuration": "standalone",
   127  					})
   128  					So(v, ShouldNotBeNil)
   129  					So(len(v.Tasks), ShouldEqual, 5)
   130  					So(v.Tags, ShouldContain, "posix")
   131  					Convey("which should contain a compile", func() {
   132  						So(v.Tasks[4].Name, ShouldEqual, "compile")
   133  						So(v.Tasks[4].Distros, ShouldResemble, []string{"linux_big"})
   134  						So(v.Tasks[4].DependsOn[0], ShouldResemble, TaskDependency{
   135  							Name:    "pre-task",
   136  							Variant: "analysis",
   137  						})
   138  					})
   139  				})
   140  				Convey("including osx/repl", func() {
   141  					v := findMatrixVariant(p.BuildVariants, matrixValue{
   142  						"os":            "osx",
   143  						"configuration": "repl",
   144  					})
   145  					So(v, ShouldNotBeNil)
   146  					So(len(v.Tasks), ShouldEqual, 4)
   147  					So(v.Tags, ShouldContain, "posix")
   148  					Convey("which should depend on another variant's compile", func() {
   149  						So(v.Tasks[0].Name, ShouldEqual, "test1")
   150  						So(v.Tasks[0].DependsOn[0].Name, ShouldEqual, "compile")
   151  						So(v.Tasks[0].DependsOn[0].Variant, ShouldNotEqual, "")
   152  					})
   153  				})
   154  			})
   155  
   156  			Convey("and contain the correct tasks", func() {
   157  				So(len(p.Tasks), ShouldEqual, 7)
   158  				Convey("such that post-task depends on everything", func() {
   159  					pt := ProjectTask{}
   160  					for _, t := range p.Tasks {
   161  						if t.Name == "post-task" {
   162  							pt = t
   163  						}
   164  					}
   165  					So(pt.Name, ShouldEqual, "post-task")
   166  					So(len(pt.DependsOn), ShouldEqual, 4*(3*3))
   167  				})
   168  			})
   169  		})
   170  	})
   171  }