Пример #1
0
func TestPluginLoad(t *testing.T) {
	plugin := testPlugin(t, "mock")
	if err := plugin.Load(); err != nil {
		t.Fatalf("err: %s", err)
	}

	if !reflect.DeepEqual(plugin.AppMeta, testPluginMockMeta) {
		t.Fatalf("bad: %#v", plugin.AppMeta)
	}
}
Пример #2
0
func TestPluginLoad_used(t *testing.T) {
	plugin := testPlugin(t, "mock")
	if err := plugin.Load(); err != nil {
		t.Fatalf("err: %s", err)
	}

	if plugin.Used() {
		t.Fatal("should not be used")
	}

	if _, err := plugin.App(); err != nil {
		t.Fatalf("err: %s", err)
	}

	if !plugin.Used() {
		t.Fatal("should be used")
	}
}
Пример #3
0
// LoadAll will launch every plugin and add it to the CoreConfig given.
func (m *PluginManager) LoadAll() error {
	// If we've never loaded plugin paths, then let's discover those first
	if m.Plugins() == nil {
		if err := m.Discover(); err != nil {
			return err
		}
	}

	// Go through each plugin path and load single
	var merr error
	var merrLock sync.Mutex
	var wg sync.WaitGroup
	sema := semaphore.New(runtime.NumCPU())
	for _, plugin := range m.Plugins() {
		wg.Add(1)
		go func(plugin *Plugin) {
			defer wg.Done()

			sema.Acquire()
			defer sema.Release()

			if err := plugin.Load(); err != nil {
				merrLock.Lock()
				defer merrLock.Unlock()
				merr = multierror.Append(merr, fmt.Errorf(
					"Error loading plugin %s: %s",
					plugin.Path, err))
			}
		}(plugin)
	}

	// Wait for all the plugins to load
	wg.Wait()

	return merr
}