-
Notifications
You must be signed in to change notification settings - Fork 205
/
helpers.go
71 lines (59 loc) · 2.12 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
64
65
66
67
68
69
70
71
package cnabprovider
import (
"testing"
"get.porter.sh/porter/pkg/claims"
"get.porter.sh/porter/pkg/cnab"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/context"
"get.porter.sh/porter/pkg/credentials"
"get.porter.sh/porter/pkg/parameters"
"get.porter.sh/porter/pkg/storage"
"github.com/stretchr/testify/require"
)
const debugDriver = "debug"
var _ CNABProvider = &TestRuntime{}
type TestRuntime struct {
*Runtime
TestStorage storage.TestStore
TestClaims *claims.TestClaimProvider
TestCredentials *credentials.TestCredentialProvider
TestParameters *parameters.TestParameterProvider
TestConfig *config.TestConfig
}
func NewTestRuntime(t *testing.T) *TestRuntime {
tc := config.NewTestConfig(t)
testStorage := storage.NewTestStore(tc.TestContext)
testClaims := claims.NewTestClaimProviderFor(tc.TestContext.T, testStorage)
testCredentials := credentials.NewTestCredentialProviderFor(tc.TestContext.T, testStorage)
testParameters := parameters.NewTestParameterProviderFor(tc.TestContext.T, testStorage)
return NewTestRuntimeFor(tc, testClaims, testCredentials, testParameters)
}
func NewTestRuntimeFor(tc *config.TestConfig, testClaims *claims.TestClaimProvider, testCredentials *credentials.TestCredentialProvider, testParameters *parameters.TestParameterProvider) *TestRuntime {
return &TestRuntime{
TestConfig: tc,
TestClaims: testClaims,
TestCredentials: testCredentials,
TestParameters: testParameters,
Runtime: NewRuntime(tc.Config, testClaims, testCredentials),
}
}
func (t *TestRuntime) Teardown() error {
t.TestClaims.Teardown()
t.TestCredentials.Teardown()
t.TestParameters.Teardown()
return nil
}
func (t *TestRuntime) LoadBundle(bundleFile string) (cnab.ExtendedBundle, error) {
return t.Runtime.LoadBundle(bundleFile)
}
func (t *TestRuntime) LoadTestBundle(bundleFile string) cnab.ExtendedBundle {
bun, err := cnab.LoadBundle(context.New(), bundleFile)
require.NoError(t.TestConfig.TestContext.T, err)
return bun
}
func (t *TestRuntime) Execute(args ActionArguments) error {
if args.Driver == "" {
args.Driver = debugDriver
}
return t.Runtime.Execute(args)
}