Skip to content

Commit 5ed8a1c

Browse files
committed
tests: add imports test
1 parent d4ce40e commit 5ed8a1c

File tree

15 files changed

+166
-59
lines changed

15 files changed

+166
-59
lines changed

cmd/deploy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,16 @@ func runPipeline(ctx *devspacecontext.Context, f factory.Factory, forceLeader bo
307307
} else if !couldExclude {
308308
return fmt.Errorf("couldn't execute '%s', because there is another DevSpace instance active in the current namespace right now that uses the same project name (%s)", strings.Join(os.Args, " "), ctx.Config.Config().Name)
309309
}
310+
ctx.Log.Debugf("Marked project excluded: %v", ctx.Config.Config().Name)
310311

311312
// start pipeline
312313
err = pipe.Run(ctx.WithLogger(ctx.Log.WithoutPrefix()))
313314
if err != nil {
314315
return err
315316
}
316317

318+
ctx.Log.Debugf("Wait for dev to finish")
319+
317320
// wait for dev
318321
pipe.WaitDev()
319322

e2e/e2e_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
_ "github.com/loft-sh/devspace/e2e/tests/deploy"
1717
_ "github.com/loft-sh/devspace/e2e/tests/devspacehelper"
1818
_ "github.com/loft-sh/devspace/e2e/tests/hooks"
19+
_ "github.com/loft-sh/devspace/e2e/tests/imports"
1920
_ "github.com/loft-sh/devspace/e2e/tests/init"
2021
_ "github.com/loft-sh/devspace/e2e/tests/render"
2122
_ "github.com/loft-sh/devspace/e2e/tests/replacepods"

e2e/framework/helper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ func ExpectLocalFileContents(filePath string, contents string) {
135135
ExpectNoErrorWithOffset(1, err)
136136
}
137137

138+
func ExpectLocalFileContentsWithoutSpaces(filePath string, contents string) {
139+
out, err := ioutil.ReadFile(filePath)
140+
ExpectNoError(err)
141+
gomega.ExpectWithOffset(2, strings.TrimSpace(string(out))).To(gomega.Equal(contents))
142+
}
143+
138144
func ExpectLocalFileNotFound(filePath string) {
139145
_, err := os.Stat(filePath)
140146
gomega.ExpectWithOffset(1, os.IsNotExist(err)).Should(gomega.BeTrue())

e2e/tests/imports/framework.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package imports
2+
3+
import "github.com/onsi/ginkgo"
4+
5+
// DevSpaceDescribe annotates the test with the label.
6+
func DevSpaceDescribe(text string, body func()) bool {
7+
return ginkgo.Describe("[imports] "+text, body)
8+
}

e2e/tests/imports/imports.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package imports
2+
3+
import (
4+
"github.com/loft-sh/devspace/cmd"
5+
"github.com/loft-sh/devspace/cmd/flags"
6+
"github.com/loft-sh/devspace/e2e/framework"
7+
"github.com/loft-sh/devspace/e2e/kube"
8+
"github.com/loft-sh/devspace/pkg/util/factory"
9+
"github.com/onsi/ginkgo"
10+
"os"
11+
)
12+
13+
var _ = DevSpaceDescribe("imports", func() {
14+
initialDir, err := os.Getwd()
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
// create a new factory
20+
var (
21+
f factory.Factory
22+
kubeClient *kube.KubeHelper
23+
)
24+
25+
ginkgo.BeforeEach(func() {
26+
f = framework.NewDefaultFactory()
27+
28+
kubeClient, err = kube.NewKubeHelper()
29+
framework.ExpectNoError(err)
30+
})
31+
32+
ginkgo.FIt("should import correctly", func() {
33+
tempDir, err := framework.CopyToTempDir("tests/imports/testdata/local")
34+
framework.ExpectNoError(err)
35+
defer framework.CleanupTempDir(initialDir, tempDir)
36+
37+
ns, err := kubeClient.CreateNamespace("imports")
38+
framework.ExpectNoError(err)
39+
defer func() {
40+
err := kubeClient.DeleteNamespace(ns)
41+
framework.ExpectNoError(err)
42+
}()
43+
44+
// create a new dev command
45+
deployCmd := &cmd.DeployCmd{
46+
GlobalFlags: &flags.GlobalFlags{
47+
NoWarn: true,
48+
Namespace: ns,
49+
},
50+
}
51+
52+
// run the command
53+
err = deployCmd.Run(f)
54+
framework.ExpectNoError(err)
55+
framework.ExpectLocalFileContentsWithoutSpaces("dependency.txt", "import3")
56+
framework.ExpectLocalFileContentsWithoutSpaces("import1.txt", "import1")
57+
framework.ExpectLocalFileContentsWithoutSpaces("import2.txt", "import2")
58+
framework.ExpectLocalFileContentsWithoutSpaces("import3.txt", "import3")
59+
framework.ExpectLocalFileContentsWithoutSpaces("vars.txt", ns+"-"+ns+"-base-import1-import2-import3")
60+
})
61+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: v2beta1
2+
name: base
3+
4+
imports:
5+
- path: import1.yaml
6+
- path: import2.yaml
7+
8+
vars:
9+
BASE: base
10+
11+
dependencies:
12+
import1:
13+
path: import1.yaml
14+
pipeline: import3
15+
16+
pipelines:
17+
deploy:
18+
steps:
19+
- run: |-
20+
run_dependency_pipelines --all > dependency.txt
21+
22+
run_pipelines import1 > import1.txt
23+
run_pipelines import2 > import2.txt
24+
run_pipelines import3 > import3.txt
25+
26+
echo ${DEVSPACE_NAMESPACE}-${devspace.namespace}-${BASE}-${IMPORT1}-${IMPORT2}-${IMPORT3} > vars.txt
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: v2beta1
2+
name: import1
3+
4+
imports:
5+
- path: import3.yaml
6+
7+
vars:
8+
IMPORT1: import1
9+
10+
pipelines:
11+
import1:
12+
steps:
13+
- run: |-
14+
echo ${IMPORT1}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v2beta1
2+
name: import2
3+
4+
vars:
5+
IMPORT2: import2
6+
7+
pipelines:
8+
import2:
9+
steps:
10+
- run: |-
11+
echo ${IMPORT2}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v2beta1
2+
name: import3
3+
4+
vars:
5+
IMPORT3: import3
6+
7+
pipelines:
8+
import3:
9+
steps:
10+
- run: |-
11+
echo ${IMPORT3}

pkg/devspace/config/loader/validate.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ func validateDependencies(config *latest.Config) error {
125125
return errors.Errorf("dependencies[%s].source is required", name)
126126
}
127127
if dep.Source.Git == "" && dep.Source.Path == "" {
128-
return errors.Errorf("dependencies[%s].source.git or dependencies[%s].source.path is required", name, name)
129-
}
130-
if len(dep.Profiles) > 0 && dep.Profile != "" {
131-
return errors.Errorf("dependencies[%s].profiles and dependencies[%s].profile & dependencies[%s].profileParents cannot be used together", name, name, name)
128+
return errors.Errorf("dependencies[%s].git or dependencies[%s].path is required", name, name)
132129
}
133130
}
134131

0 commit comments

Comments
 (0)