Skip to content

Commit d6f711c

Browse files
committed
tests: add git dependency e2e test
1 parent fd10218 commit d6f711c

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

e2e/framework/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func ExpectRemoteFileContents(imageSelector string, namespace string, filePath s
7070
return false, nil
7171
}
7272

73-
return out == contents, nil
73+
return strings.TrimSpace(out) == strings.TrimSpace(contents), nil
7474
})
7575
ExpectNoErrorWithOffset(1, err)
7676
}

e2e/tests/dependencies/dependencies.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package dependencies
22

33
import (
44
"context"
5+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
6+
dependencyutil "github.com/loft-sh/devspace/pkg/devspace/dependency/util"
57
"github.com/loft-sh/devspace/pkg/devspace/kubectl/selector"
8+
"io/ioutil"
69
corev1 "k8s.io/api/core/v1"
710
"k8s.io/apimachinery/pkg/util/wait"
811
"os"
@@ -38,6 +41,67 @@ var _ = DevSpaceDescribe("dependencies", func() {
3841
kubeClient, err = kube.NewKubeHelper()
3942
})
4043

44+
ginkgo.It("should deploy git dependency", func() {
45+
tempDir, err := framework.CopyToTempDir("tests/dependencies/testdata/git")
46+
framework.ExpectNoError(err)
47+
defer framework.CleanupTempDir(initialDir, tempDir)
48+
49+
ns, err := kubeClient.CreateNamespace("dependencies")
50+
framework.ExpectNoError(err)
51+
defer func() {
52+
err := kubeClient.DeleteNamespace(ns)
53+
framework.ExpectNoError(err)
54+
}()
55+
56+
// create a new dev command and start it
57+
done := make(chan error)
58+
cancelCtx, cancel := context.WithCancel(context.Background())
59+
defer cancel()
60+
go func() {
61+
devCmd := &cmd.DevCmd{
62+
GlobalFlags: &flags.GlobalFlags{
63+
NoWarn: true,
64+
Namespace: ns,
65+
},
66+
Ctx: cancelCtx,
67+
}
68+
err := devCmd.Run(f)
69+
if err != nil {
70+
f.GetLog().Errorf("error: %v", err)
71+
}
72+
done <- err
73+
}()
74+
75+
// make sure the dependencies are correctly deployed
76+
id, err := dependencyutil.GetDependencyID(&latest.SourceConfig{
77+
Git: "https://github.com/loft-sh/e2e-test-dependency.git",
78+
})
79+
framework.ExpectNoError(err)
80+
81+
// calculate dependency path
82+
dependencyPath := filepath.Join(dependencyutil.DependencyFolderPath, id)
83+
84+
// wait until file is there
85+
framework.ExpectLocalFileContents("imports.txt", "Test-dep-test\n")
86+
framework.ExpectLocalFileContents(filepath.Join(dependencyPath, "dependency-dev.txt"), "Hello I am dependency\n")
87+
framework.ExpectLocalFileContents(filepath.Join(dependencyPath, "dependency-deploy.txt"), "Hello I am dependency-deploy\n")
88+
framework.ExpectLocalFileContents("dependency.txt", "Hello again I am dependency-deploy\n")
89+
90+
// expect remote file
91+
framework.ExpectRemoteFileContents("alpine", ns, "/app/test.txt", "dependency123")
92+
93+
// now check if sync is still working
94+
err = ioutil.WriteFile(filepath.Join(dependencyPath, "test123.txt"), []byte("test123"), 0777)
95+
framework.ExpectNoError(err)
96+
97+
// now check if file gets synced
98+
framework.ExpectRemoteFileContents("alpine", ns, "/app/test123.txt", "test123")
99+
100+
cancel()
101+
err = <-done
102+
framework.ExpectNoError(err)
103+
})
104+
41105
ginkgo.It("should skip equal dependencies", func() {
42106
tempDir, err := framework.CopyToTempDir("tests/dependencies/testdata/overlapping")
43107
framework.ExpectNoError(err)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: v2beta1
2+
name: dep-test
3+
4+
imports:
5+
- git: https://github.com/loft-sh/e2e-test-dependency.git
6+
branch: imports
7+
8+
dependencies:
9+
dependency:
10+
git: https://github.com/loft-sh/e2e-test-dependency.git
11+
pipeline: dev
12+
dependency-deploy:
13+
git: https://github.com/loft-sh/e2e-test-dependency.git
14+
15+
pipelines:
16+
dev:
17+
steps:
18+
- run: |-
19+
run_dependency_pipelines dependency
20+
run_dependency_pipelines dependency-deploy > dependency.txt
21+
run_command dep-test > imports.txt

pkg/devspace/dependency/util/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func init() {
3535
}
3636

3737
func DownloadDependency(ctx context.Context, workingDirectory string, source *latest.SourceConfig, log log.Logger) (configPath string, err error) {
38-
ID, err := getDependencyID(source)
38+
ID, err := GetDependencyID(source)
3939
if err != nil {
4040
return "", err
4141
}
@@ -46,7 +46,7 @@ func DownloadDependency(ctx context.Context, workingDirectory string, source *la
4646
gitPath := strings.TrimSpace(source.Git)
4747

4848
_ = os.MkdirAll(DependencyFolderPath, 0755)
49-
localPath = filepath.Join(DependencyFolderPath, encoding.Convert(ID))
49+
localPath = filepath.Join(DependencyFolderPath, ID)
5050

5151
// Check if dependency exists
5252
_, statErr := os.Stat(localPath)
@@ -84,7 +84,7 @@ func DownloadDependency(ctx context.Context, workingDirectory string, source *la
8484
}
8585
} else if source.Path != "" {
8686
if isURL(source.Path) {
87-
localPath = filepath.Join(DependencyFolderPath, encoding.Convert(ID))
87+
localPath = filepath.Join(DependencyFolderPath, ID)
8888
_ = os.MkdirAll(localPath, 0755)
8989

9090
// Check if dependency exists
@@ -157,7 +157,7 @@ func getDependencyConfigPath(dependencyPath string, source *latest.SourceConfig)
157157
return configPath, nil
158158
}
159159

160-
func getDependencyID(source *latest.SourceConfig) (string, error) {
160+
func GetDependencyID(source *latest.SourceConfig) (string, error) {
161161
// check if source is there
162162
if source == nil {
163163
return "", fmt.Errorf("source is missing")
@@ -174,7 +174,7 @@ func getDependencyID(source *latest.SourceConfig) (string, error) {
174174
id += "@revision:" + source.Revision
175175
}
176176

177-
return id, nil
177+
return encoding.Convert(id), nil
178178
} else if source.Path != "" {
179179
return source.Path, nil
180180
}

0 commit comments

Comments
 (0)