From 8c976f7b906dc24c4dd480009aa2ff7ea9991efa Mon Sep 17 00:00:00 2001 From: Akash Kumar Date: Fri, 16 Feb 2024 15:28:52 +0530 Subject: [PATCH] test: Add unit test Signed-off-by: Akash Kumar --- pkg/client/client_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index c741e1856..2950108c3 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -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\": \"admin@admin.com\", \"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()