summaryrefslogtreecommitdiff
path: root/plugins/factory/tests/plugin_1.go
blob: a7aba98e6606d456d35e1bad6a98368d8c308ea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package tests

import (
	"errors"
	"fmt"

	"github.com/temporalio/roadrunner-temporal/config"
	"github.com/temporalio/roadrunner-temporal/factory"
)

type Foo struct {
	configProvider  config.Provider
	spawner factory.Spawner
}

func (f *Foo) Init(p config.Provider, spw factory.Spawner) error {
	f.configProvider = p
	f.spawner = spw
	return nil
}

func (f *Foo) Serve() chan error {
	errCh := make(chan error, 1)

	r := &factory.AppConfig{}
	err := f.configProvider.UnmarshalKey("app", r)
	if err != nil {
		errCh <- err
		return errCh
	}

	cmd, err := f.spawner.NewCmd(nil)
	if err != nil {
		errCh <- err
		return errCh
	}
	if cmd == nil {
		errCh <- errors.New("command is nil")
		return errCh
	}
	a := cmd()
	out, err := a.Output()
	if err != nil {
		errCh <- err
		return errCh
	}

	fmt.Println(string(out))

	return errCh
}

func (f *Foo) Stop() error {
	return nil
}