예제 #1
0
func TestPatchPlugin(t *testing.T) {
	cwd := testutil.GetDirectoryOfFile()
	testConfig := evergreen.TestConfig()
	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testConfig))
	Convey("With patch plugin installed into plugin registry", t, func() {
		registry := plugin.NewSimpleRegistry()
		gitPlugin := &GitPlugin{}
		err := registry.Register(gitPlugin)
		testutil.HandleTestingErr(err, t, "Couldn't register plugin %v")
		testutil.HandleTestingErr(db.Clear(version.Collection), t,
			"unable to clear versions collection")
		version := &version.Version{
			Id: "",
		}
		So(version.Insert(), ShouldBeNil)
		server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins, false)
		testutil.HandleTestingErr(err, t, "Couldn't set up testing server")
		httpCom := plugintest.TestAgentCommunicator("testTaskId", "testTaskSecret", server.URL)

		//sliceAppender := &evergreen.SliceAppender{[]*slogger.Log{}}
		sliceAppender := slogger.StdOutAppender()
		logger := agentutil.NewTestLogger(sliceAppender)

		Convey("all commands in test project should execute successfully", func() {
			taskConfig, err := plugintest.CreateTestConfig(filepath.Join(cwd, "testdata", "plugin_patch.yml"), t)
			testutil.HandleTestingErr(err, t, "could not create test config")

			taskConfig.Task.Requester = evergreen.PatchVersionRequester
			_, _, err = plugintest.SetupAPITestData("testTask", filepath.Join(cwd, "testdata", "testmodule.patch"), t)
			testutil.HandleTestingErr(err, t, "Couldn't set up test documents")

			for _, task := range taskConfig.Project.Tasks {
				So(len(task.Commands), ShouldNotEqual, 0)
				for _, command := range task.Commands {
					pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions)
					testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v")
					So(pluginCmds, ShouldNotBeNil)
					So(err, ShouldBeNil)
					pluginCom := &comm.TaskJSONCommunicator{pluginCmds[0].Plugin(), httpCom}
					err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, make(chan bool))
					So(err, ShouldBeNil)
				}
			}
		})
	})
}
예제 #2
0
// NewStreamLogger creates a StreamLogger wrapper for the apiLogger with a given timeoutWatcher.
// Any logged messages on the StreamLogger will reset the TimeoutWatcher.
func NewStreamLogger(timeoutWatcher *TimeoutWatcher, apiLgr *APILogger, logFile string) (*StreamLogger, error) {
	localLogger := slogger.StdOutAppender()

	if logFile != "" {
		appendingFile, err := evergreen.GetAppendingFile(logFile)
		if err != nil {
			return nil, err
		}
		localLogger = &slogger.FileAppender{appendingFile}
	}

	localLoggers := []slogger.Appender{localLogger}
	defaultLoggers := []slogger.Appender{localLogger, apiLgr}

	timeoutLogger := &TimeoutResetLogger{timeoutWatcher, apiLgr}

	return &StreamLogger{
		Local: &slogger.Logger{
			Prefix:    "local",
			Appenders: localLoggers,
		},

		System: &slogger.Logger{
			Prefix:    model.SystemLogPrefix,
			Appenders: defaultLoggers,
		},

		Task: &slogger.Logger{
			Prefix:    model.TaskLogPrefix,
			Appenders: []slogger.Appender{localLogger, timeoutLogger},
		},

		Execution: &slogger.Logger{
			Prefix:    model.AgentLogPrefix,
			Appenders: defaultLoggers,
		},
	}, nil
}
예제 #3
0
func init() {
	logger = &slogger.Logger{
		Prefix:    "test",
		Appenders: []slogger.Appender{slogger.StdOutAppender()},
	}
}
예제 #4
0
)

var (
	// UphostStatus is a list of all host statuses that are considered "up."
	// This is used for query building.
	UphostStatus = []string{
		HostRunning,
		HostUninitialized,
		HostInitializing,
		HostProvisionFailed,
	}

	// Logger is our global logger. It can be changed for testing.
	Logger = slogger.Logger{
		Prefix:    "",
		Appenders: []slogger.Appender{slogger.StdOutAppender()},
	}

	// database and config directory, set to the testing version by default for safety
	NotificationsFile = "mci-notifications.yml"

	// version requester types
	PatchVersionRequester       = "patch_request"
	RepotrackerVersionRequester = "gitter_request"

	// constant arrays for db update logic
	AbortableStatuses = []string{TaskStarted, TaskDispatched}
	CompletedStatuses = []string{TaskSucceeded, TaskFailed}
)

// SetLogger sets the global logger to write to the given path.