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

     1  package git_test
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/evergreen-ci/evergreen/agent/comm"
     9  	agentutil "github.com/evergreen-ci/evergreen/agent/testutil"
    10  	"github.com/evergreen-ci/evergreen/db"
    11  	modelutil "github.com/evergreen-ci/evergreen/model/testutil"
    12  	"github.com/evergreen-ci/evergreen/plugin"
    13  	. "github.com/evergreen-ci/evergreen/plugin/builtin/git"
    14  	"github.com/evergreen-ci/evergreen/plugin/plugintest"
    15  	"github.com/evergreen-ci/evergreen/service"
    16  	"github.com/evergreen-ci/evergreen/testutil"
    17  	"github.com/mongodb/grip/slogger"
    18  	. "github.com/smartystreets/goconvey/convey"
    19  )
    20  
    21  func init() {
    22  	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testutil.TestConfig()))
    23  }
    24  
    25  func TestGitPlugin(t *testing.T) {
    26  	testConfig := testutil.TestConfig()
    27  	Convey("With git plugin installed into plugin registry", t, func() {
    28  		registry := plugin.NewSimpleRegistry()
    29  		gitPlugin := &GitPlugin{}
    30  		err := registry.Register(gitPlugin)
    31  		testutil.HandleTestingErr(err, t, "Couldn't register plugin: %v")
    32  
    33  		server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins)
    34  		testutil.HandleTestingErr(err, t, "Couldn't set up testing server")
    35  		defer server.Close()
    36  
    37  		configPath := filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "plugin_clone.yml")
    38  		patchPath := filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "test.patch")
    39  
    40  		modelData, err := modelutil.SetupAPITestData(testConfig, "test", "rhel55", configPath, modelutil.NoPatch)
    41  		testutil.HandleTestingErr(err, t, "failed to setup test data")
    42  		err = plugintest.SetupPatchData(modelData, patchPath, t)
    43  		testutil.HandleTestingErr(err, t, "failed to setup patch data")
    44  		taskConfig := modelData.TaskConfig
    45  
    46  		httpCom := plugintest.TestAgentCommunicator(modelData, server.URL)
    47  
    48  		logger := agentutil.NewTestLogger(slogger.StdOutAppender())
    49  		Convey("all commands in test project should execute successfully", func() {
    50  			for _, task := range taskConfig.Project.Tasks {
    51  				So(len(task.Commands), ShouldNotEqual, 0)
    52  				for _, command := range task.Commands {
    53  					pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions)
    54  					testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v")
    55  					So(pluginCmds, ShouldNotBeNil)
    56  					So(err, ShouldBeNil)
    57  					pluginCom := &comm.TaskJSONCommunicator{pluginCmds[0].Plugin(), httpCom}
    58  					err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, make(chan bool))
    59  					So(err, ShouldBeNil)
    60  				}
    61  			}
    62  			err = os.RemoveAll(taskConfig.WorkDir)
    63  			testutil.HandleTestingErr(err, t, "Couldn't clean up test temp dir")
    64  		})
    65  	})
    66  }