github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/taskrunner/task_runner_test.go (about)

     1  package taskrunner
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/evergreen-ci/evergreen"
     7  	"github.com/evergreen-ci/evergreen/db"
     8  	"github.com/evergreen-ci/evergreen/model/host"
     9  	"github.com/evergreen-ci/evergreen/testutil"
    10  	"github.com/mongodb/grip"
    11  	. "github.com/smartystreets/goconvey/convey"
    12  )
    13  
    14  var taskRunnerTestConf = testutil.TestConfig()
    15  var agtRevision = "abc"
    16  
    17  func init() {
    18  	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(taskRunnerTestConf))
    19  	grip.CatchError(grip.SetSender(testutil.SetupTestSender(taskRunnerTestConf.TaskRunner.LogFile)))
    20  }
    21  
    22  type MockHostGateway struct{}
    23  
    24  func (self *MockHostGateway) RunSetup() error {
    25  	return nil
    26  }
    27  
    28  func (self *MockHostGateway) GetAgentRevision() (string, error) {
    29  	return agtRevision, nil
    30  }
    31  
    32  func (self *MockHostGateway) StartAgentOnHost(settings *evergreen.Settings,
    33  	targetHost host.Host) error {
    34  	return nil
    35  }
    36  
    37  func (self *MockHostGateway) AgentNeedsBuild() (bool, error) {
    38  	return false, nil
    39  }
    40  
    41  func TestTaskRunner(t *testing.T) {
    42  	Convey("with a mocked task runner and a free host", t, func() {
    43  		if err := db.ClearCollections(host.Collection); err != nil {
    44  			t.Fatalf("clearing db: %v", err)
    45  		}
    46  		tr := TaskRunner{
    47  			taskRunnerTestConf,
    48  			&MockHostGateway{},
    49  		}
    50  
    51  		h1 := host.Host{
    52  			Id:          "host1",
    53  			Status:      evergreen.HostRunning,
    54  			RunningTask: "tid",
    55  		}
    56  		So(h1.Insert(), ShouldBeNil)
    57  
    58  		Convey("running the task runner should modify the host's revision", func() {
    59  			So(tr.Run(), ShouldBeNil)
    60  		})
    61  
    62  	})
    63  }