-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: run remote repo in kpm run (#251)
* feat: run remote repo in kpm run Signed-off-by: Akash Kumar <[email protected]> * address review comments Signed-off-by: Akash Kumar <[email protected]> * test: Add unit test Signed-off-by: Akash Kumar <[email protected]> --------- Signed-off-by: Akash Kumar <[email protected]>
- Loading branch information
1 parent
bd65b2a
commit f67db1b
Showing
10 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"github.com/otiai10/copy" | ||
"github.com/stretchr/testify/assert" | ||
"kcl-lang.io/kpm/pkg/env" | ||
"kcl-lang.io/kpm/pkg/git" | ||
"kcl-lang.io/kpm/pkg/opt" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
"kcl-lang.io/kpm/pkg/runner" | ||
|
@@ -844,6 +845,29 @@ func TestRunWithNoSumCheck(t *testing.T) { | |
}() | ||
} | ||
|
||
func TestRemoteRun(t *testing.T) { | ||
kpmcli, err := NewKpmClient() | ||
assert.Equal(t, err, nil) | ||
|
||
opts := opt.DefaultCompileOptions() | ||
gitOpts := git.NewCloneOptions("https://github.com/KusionStack/catalog", "", "0.1.2", "", "", nil) | ||
|
||
opts.SetEntries([]string{"models/samples/hellocollaset/prod/main.k"}) | ||
result, err := kpmcli.CompileGitPkg(gitOpts, opts) | ||
assert.Equal(t, err, nil) | ||
assert.Equal(t, result.GetRawJsonResult(), "[{\"hellocollaset\": {\"workload\": {\"containers\": {\"nginx\": {\"image\": \"nginx:v2\"}}}}}]") | ||
|
||
opts.SetEntries([]string{"models/samples/pgadmin/base/base.k"}) | ||
result, err = kpmcli.CompileGitPkg(gitOpts, opts) | ||
assert.Equal(t, err, nil) | ||
assert.Equal(t, result.GetRawJsonResult(), "[{\"pgadmin\": {\"workload\": {\"containers\": {\"pgadmin\": {\"image\": \"dpage/pgadmin4:latest\", \"env\": {\"PGADMIN_DEFAULT_EMAIL\": \"[email protected]\", \"PGADMIN_DEFAULT_PASSWORD\": \"secret://pgadmin-secret/pgadmin-default-password\", \"PGADMIN_PORT\": \"80\"}, \"resources\": {\"cpu\": \"500m\", \"memory\": \"512Mi\"}}}, \"secrets\": {\"pgadmin-secret\": {\"type\": \"opaque\", \"data\": {\"pgadmin-default-password\": \"*******\"}}}, \"replicas\": 1, \"ports\": [{\"port\": 80, \"protocol\": \"TCP\", \"public\": false}]}, \"database\": {\"pgadmin\": {\"type\": \"cloud\", \"version\": \"14.0\"}}}}]") | ||
|
||
opts.SetEntries([]string{"models/samples/wordpress/prod/main.k"}) | ||
result, err = kpmcli.CompileGitPkg(gitOpts, opts) | ||
assert.Equal(t, err, nil) | ||
assert.Equal(t, result.GetRawJsonResult(), "[{\"wordpress\": {\"workload\": {\"containers\": {\"wordpress\": {\"image\": \"wordpress:6.3\", \"env\": {\"WORDPRESS_DB_HOST\": \"$(KUSION_DB_HOST_WORDPRESS)\", \"WORDPRESS_DB_USER\": \"$(KUSION_DB_USERNAME_WORDPRESS)\", \"WORDPRESS_DB_PASSWORD\": \"$(KUSION_DB_PASSWORD_WORDPRESS)\", \"WORDPRESS_DB_NAME\": \"mysql\"}, \"resources\": {\"cpu\": \"500m\", \"memory\": \"512Mi\"}}}, \"replicas\": 1, \"ports\": [{\"port\": 80, \"protocol\": \"TCP\", \"public\": false}]}, \"database\": {\"wordpress\": {\"type\": \"cloud\", \"version\": \"8.0\"}}}}]") | ||
} | ||
|
||
func TestUpdateWithNoSumCheck(t *testing.T) { | ||
pkgPath := getTestDir("test_update_no_sum_check") | ||
kpmcli, err := NewKpmClient() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,40 @@ func TestIsUrl(t *testing.T) { | |
assert.Equal(t, IsURL("https://"), false) | ||
} | ||
|
||
func TestIsGitRepoUrl(t *testing.T) { | ||
assert.Equal(t, IsGitRepoUrl("invalid url"), false) | ||
assert.Equal(t, IsGitRepoUrl("ftp://github.com/user/project.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("file:///path/to/repo.git/"), false) | ||
assert.Equal(t, IsGitRepoUrl("file://~/path/to/repo.git/"), false) | ||
assert.Equal(t, IsGitRepoUrl("path/to/repo.git/"), false) | ||
assert.Equal(t, IsGitRepoUrl("~/path/to/repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("rsync://host.xz/path/to/repo.git/"), false) | ||
assert.Equal(t, IsGitRepoUrl("host.xz:path/to/repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("[email protected]:path/to/repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("C:\\path\\to\\repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("/path/to/repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("./path/to/repo.git"), false) | ||
assert.Equal(t, IsGitRepoUrl("oci://host.xz/path/to/repo.git/"), false) | ||
assert.Equal(t, IsGitRepoUrl("https://github.com/user/project"), true) | ||
assert.Equal(t, IsGitRepoUrl("[email protected]:user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("https://github.com/user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("https://github.com/user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("[email protected]:user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("https://192.168.101.127/user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("http://192.168.101.127/user/project.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://[email protected]:port/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://[email protected]/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://host.xz:port/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://host.xz/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://[email protected]/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://[email protected]/~user/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://host.xz/~user/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("ssh://[email protected]/~/path/to/repo.git"), true) | ||
assert.Equal(t, IsGitRepoUrl("git://host.xz/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("http://host.xz/path/to/repo.git/"), true) | ||
assert.Equal(t, IsGitRepoUrl("https://host.xz/path/to/repo.git/"), true) | ||
} | ||
|
||
func TestIsRef(t *testing.T) { | ||
assert.Equal(t, IsRef("invalid ref"), false) | ||
assert.Equal(t, IsRef("ghcr.io/xxx/xxx"), true) | ||
|