Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared folder to artifacts #41

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/GetStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Create a Test](#create-a-test)
- [Input Contract](#input-contract)
- [Export Contract](#export-contract)
- [Shared Folder](#shared-folder)
- [Images](#images)
- [Create a Testrun](#create-a-testrun)
- [Configuration](#configuration)
Expand Down Expand Up @@ -117,6 +118,10 @@ It then automatically uploads these documents to an index named like the TestDef
{ "key3": 5 }
```

### Shared Folder

Data that is stored in `TM_SHARED_PATH` location, can be accessed from within any testflow step of a the workflow. This is essential if e.g. a test flow step needs to evaluate the output of the previously finished test flow step. This folder is also available as an artifact in the Argo UI.

### Images

The Testmachinery provides some images to run your Integration Tests (Dockerfiles can be found in hack/images).
Expand Down
9 changes: 9 additions & 0 deletions pkg/testmachinery/testdefinition/testdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func New(def *tmv1beta1.TestDefinition, loc Location, fileName string) *TestDefi
Name: "kubeconfigs",
Path: testmachinery.TM_KUBECONFIG_PATH,
},
{
Name: "sharedFolder",
Path: testmachinery.TM_SHARED_PATH,
},
},
},
Outputs: argov1.Outputs{
Expand Down Expand Up @@ -198,6 +202,11 @@ func (td *TestDefinition) AddSerialStdOutput() {
Path: testmachinery.TM_KUBECONFIG_PATH,
}
td.AddOutputArtifacts(kubeconfigArtifact)
sharedFolderArtifact := argov1.Artifact{
Name: "sharedFolder",
Path: testmachinery.TM_SHARED_PATH,
}
td.AddOutputArtifacts(sharedFolderArtifact)
}

// AddConfig adds the config elements of different types (environment variable) to the TestDefinitions's template.
Expand Down
4 changes: 4 additions & 0 deletions pkg/testmachinery/testflow/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (n *Node) addTask(lastSerialNode, rootNode *Node) {
Name: "kubeconfigs",
From: fmt.Sprintf("{{tasks.%s.outputs.artifacts.kubeconfigs}}", lastSerialNode.Task.Name),
},
{
Name: "sharedFolder",
From: fmt.Sprintf("{{tasks.%s.outputs.artifacts.sharedFolder}}", lastSerialNode.Task.Name),
},
}

if n.TestDefinition.Location.Type() != tmv1beta1.LocationTypeLocal {
Expand Down
5 changes: 4 additions & 1 deletion pkg/testmachinery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (

const (
// TM_KUBECONFIG_PATH is the path where kubeconfigs are mounted to tests.
TM_KUBECONFIG_PATH = "/tmp/env/kubeconfig"
TM_KUBECONFIG_PATH = "/tmp/tm/kubeconfig"

// TM_SHARED_PATH is the path to a shared folder, where content is shared among the workflow steps
TM_SHARED_PATH = "/tmp/tm/shared"

// TM_REPO_PATH is the path where the repo/location is mounted to the tests.
TM_REPO_PATH = "/src"
Expand Down
47 changes: 47 additions & 0 deletions test/controller/testflow/testflow_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package testflow_test

import (
"context"
"fmt"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -177,6 +178,52 @@ var _ = Describe("Testflow execution tests", func() {
})
})

Context("File created in shared folder", func() {
sharedFilePath := fmt.Sprintf("%s/%s", testmachinery.TM_SHARED_PATH, "test")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to test if not needed in other tests

It("should be visible from withing another step", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr.Spec.TestFlow = [][]tmv1beta1.TestflowStep{
// create file in shared folder
{
{
Name: "check-file-testdef",
Config: []tmv1beta1.ConfigElement{
{
Type: tmv1beta1.ConfigTypeEnv,
Name: "FILE",
Value: sharedFilePath,
},
{
Type: tmv1beta1.ConfigTypeFile,
Name: "TEST_NAME",
Value: "dGVzdAo=", // base64 encoded 'test' string
Path: sharedFilePath,
},
},
},
},
// check in a another step if file exists in shared folder
{
{
Name: "check-file-testdef",
Config: []tmv1beta1.ConfigElement{
{
Type: tmv1beta1.ConfigTypeEnv,
Name: "FILE",
Value: sharedFilePath,
},
},
},
},
}
tr, _, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
Expect(err).ToNot(HaveOccurred())
})
})

Context("config", func() {
Context("type environment variable", func() {
It("should mount a config as environment variable", func() {
Expand Down