-
Notifications
You must be signed in to change notification settings - Fork 158
/
helpers.go
63 lines (49 loc) 路 1.31 KB
/
helpers.go
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
56
57
58
59
60
61
62
63
package prometheus
import (
"context"
"fmt"
"os"
"os/exec"
"testing"
"github.com/slok/sloth/test/integration/testutils"
)
type Config struct {
Binary string
}
func (c *Config) defaults() error {
if c.Binary == "" {
c.Binary = "sloth"
}
_, err := exec.LookPath(c.Binary)
if err != nil {
return fmt.Errorf("sloth binary missing in %q: %w", c.Binary, err)
}
return nil
}
// NewIntegrationConfig prepares the configuration for integration tests, if the configuration is not ready
// it will skip the test.
func NewConfig(t *testing.T) Config {
const (
envSlothBin = "SLOTH_INTEGRATION_BINARY"
)
c := Config{
Binary: os.Getenv(envSlothBin),
}
err := c.defaults()
if err != nil {
t.Skipf("Skipping due to invalid config: %s", err)
}
return c
}
func RunSlothGenerate(ctx context.Context, config Config, cmdArgs string) (stdout, stderr []byte, err error) {
env := []string{
fmt.Sprintf("SLOTH_SLI_PLUGINS_PATH=%s", "./"),
}
return testutils.RunSloth(ctx, env, config.Binary, fmt.Sprintf("generate %s", cmdArgs), true)
}
func RunSlothValidate(ctx context.Context, config Config, cmdArgs string) (stdout, stderr []byte, err error) {
env := []string{
fmt.Sprintf("SLOTH_SLI_PLUGINS_PATH=%s", "./"),
}
return testutils.RunSloth(ctx, env, config.Binary, fmt.Sprintf("validate %s", cmdArgs), true)
}