diff --git a/cli/cli/kurtosis_package/kurtosis_package_test.go b/cli/cli/kurtosis_package/kurtosis_package_test.go index bb2f0b8351..165d7624cd 100644 --- a/cli/cli/kurtosis_package/kurtosis_package_test.go +++ b/cli/cli/kurtosis_package/kurtosis_package_test.go @@ -11,21 +11,24 @@ import ( ) const ( - isExecutablePackage = true - isNotExecutablePackage = false + isExecutablePackage = true + isNotExecutablePackage = false + myTestPackage = "github.com/org/my-package" + mySecondTestPackage = "github.com/org/second-package" + packageInitializeTestDirPattern = "package-initialize-test-dir-*" ) func TestInitializeKurtosisPackage_Success(t *testing.T) { - packageDirpath, err := os.MkdirTemp("", "package-initialize-test-dir-*") + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) require.NoError(t, err) defer os.RemoveAll(packageDirpath) - packageName := "github.com/org/my-package" + packageName := myTestPackage err = InitializeKurtosisPackage(packageDirpath, packageName, isExecutablePackage) require.NoError(t, err) // check kurtosis.yml file creation - expectedKurtosisYamlFilepath := path.Join(packageDirpath, "kurtosis.yml") + expectedKurtosisYamlFilepath := path.Join(packageDirpath, kurtosisYmlFilename) fileBytes, err := os.ReadFile(expectedKurtosisYamlFilepath) require.NoError(t, err) @@ -39,23 +42,23 @@ func TestInitializeKurtosisPackage_Success(t *testing.T) { require.Equal(t, packageName, kurtosisYamlObj.PackageName) // check main.star file creation - expectedMainStarFilepath := path.Join(packageDirpath, "main.star") + expectedMainStarFilepath := path.Join(packageDirpath, mainStarFilename) fileBytes, err = os.ReadFile(expectedMainStarFilepath) require.NoError(t, err) require.Equal(t, mainStarFileContentStr, string(fileBytes)) } func TestInitializeKurtosisPackage_IsNotExecutablePackageSuccess(t *testing.T) { - packageDirpath, err := os.MkdirTemp("", "package-initialize-test-dir-*") + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) require.NoError(t, err) defer os.RemoveAll(packageDirpath) - packageName := "github.com/org/my-package" + packageName := myTestPackage err = InitializeKurtosisPackage(packageDirpath, packageName, isNotExecutablePackage) require.NoError(t, err) // check kurtosis.yml file creation - expectedKurtosisYamlFilepath := path.Join(packageDirpath, "kurtosis.yml") + expectedKurtosisYamlFilepath := path.Join(packageDirpath, kurtosisYmlFilename) fileBytes, err := os.ReadFile(expectedKurtosisYamlFilepath) require.NoError(t, err) @@ -69,7 +72,7 @@ func TestInitializeKurtosisPackage_IsNotExecutablePackageSuccess(t *testing.T) { require.Equal(t, packageName, kurtosisYamlObj.PackageName) // check main.star file was not created - expectedMainStarFilepath := path.Join(packageDirpath, "main.star") + expectedMainStarFilepath := path.Join(packageDirpath, mainStarFilename) fileBytes, err = os.ReadFile(expectedMainStarFilepath) require.Error(t, err) require.True(t, os.IsNotExist(err)) @@ -77,19 +80,19 @@ func TestInitializeKurtosisPackage_IsNotExecutablePackageSuccess(t *testing.T) { } func TestInitializeKurtosisPackage_FailsIfKurtosisYmlAlreadyExist(t *testing.T) { - packageDirpath, err := os.MkdirTemp("", "package-initialize-test-dir-*") + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) require.NoError(t, err) defer os.RemoveAll(packageDirpath) - packageName := "github.com/org/my-package" + packageName := myTestPackage err = InitializeKurtosisPackage(packageDirpath, packageName, isExecutablePackage) require.NoError(t, err) - expectedKurtosisYamlFilepath := path.Join(packageDirpath, "kurtosis.yml") + expectedKurtosisYamlFilepath := path.Join(packageDirpath, kurtosisYmlFilename) fileBytes, err := os.ReadFile(expectedKurtosisYamlFilepath) require.NoError(t, err) - secondPackageName := "github.com/org/second-package" + secondPackageName := mySecondTestPackage err = InitializeKurtosisPackage(packageDirpath, secondPackageName, isExecutablePackage) require.Error(t, err) expectedErrorMsgPortion := "'kurtosis.yml' already exist on this path" @@ -108,25 +111,22 @@ func TestInitializeKurtosisPackage_FailsIfKurtosisYmlAlreadyExist(t *testing.T) } func TestInitializeKurtosisPackage_FailsIfMainStarFileAlreadyExist(t *testing.T) { - packageDirpath, err := os.MkdirTemp("", "package-initialize-test-dir-*") + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) require.NoError(t, err) defer os.RemoveAll(packageDirpath) - packageName := "github.com/org/my-package" - err = InitializeKurtosisPackage(packageDirpath, packageName, isExecutablePackage) - require.NoError(t, err) - - expectedKurtosisYamlFilepath := path.Join(packageDirpath, "kurtosis.yml") + // there is a main.star file inside the folder before initializing the package + mainStarFilepath := path.Join(packageDirpath, mainStarFilename) - err = os.Remove(expectedKurtosisYamlFilepath) + _, err = os.Create(mainStarFilepath) require.NoError(t, err) - secondPackageName := "github.com/org/second-package" - err = InitializeKurtosisPackage(packageDirpath, secondPackageName, isExecutablePackage) - require.Error(t, err) - expectedErrorMsgPortion := "'main.star' already exist on this path" - require.Contains(t, stacktrace.RootCause(err).Error(), expectedErrorMsgPortion) + packageName := myTestPackage + err = InitializeKurtosisPackage(packageDirpath, packageName, isNotExecutablePackage) + require.NoError(t, err) + // check kurtosis.yml file creation + expectedKurtosisYamlFilepath := path.Join(packageDirpath, kurtosisYmlFilename) fileBytes, err := os.ReadFile(expectedKurtosisYamlFilepath) require.NoError(t, err) @@ -135,20 +135,50 @@ func TestInitializeKurtosisPackage_FailsIfMainStarFileAlreadyExist(t *testing.T) PackageDescription: "", PackageReplaceOptions: map[string]string{}, } - err = yaml.UnmarshalStrict(fileBytes, kurtosisYamlObj) require.NoError(t, err) + require.Equal(t, packageName, kurtosisYamlObj.PackageName) - require.Equal(t, secondPackageName, kurtosisYamlObj.PackageName) } func TestInitializeKurtosisPackage_InvalidPackageNameError(t *testing.T) { - packageDirpath, err := os.MkdirTemp("", "package-initialize-test-dir-*") + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) require.NoError(t, err) defer os.RemoveAll(packageDirpath) - packageName := "my-rul/org/my-package" + packageName := "my-url/org/my-package" err = InitializeKurtosisPackage(packageDirpath, packageName, isExecutablePackage) require.Error(t, err) require.ErrorContains(t, err, "invalid GitHub URL") } + +func TestInitializeKurtosisPackage_MakeScriptPackageSuccess(t *testing.T) { + packageDirpath, err := os.MkdirTemp("", packageInitializeTestDirPattern) + require.NoError(t, err) + defer os.RemoveAll(packageDirpath) + + packageName := myTestPackage + err = InitializeKurtosisPackage(packageDirpath, packageName, isExecutablePackage) + require.NoError(t, err) + + expectedKurtosisYamlFilepath := path.Join(packageDirpath, kurtosisYmlFilename) + fileBytes, err := os.ReadFile(expectedKurtosisYamlFilepath) + require.NoError(t, err) + + secondPackageName := mySecondTestPackage + err = InitializeKurtosisPackage(packageDirpath, secondPackageName, isExecutablePackage) + require.Error(t, err) + expectedErrorMsgPortion := "'kurtosis.yml' already exist on this path" + require.Contains(t, stacktrace.RootCause(err).Error(), expectedErrorMsgPortion) + + kurtosisYamlObj := &enclaves.KurtosisYaml{ + PackageName: "", + PackageDescription: "", + PackageReplaceOptions: map[string]string{}, + } + + err = yaml.UnmarshalStrict(fileBytes, kurtosisYamlObj) + require.NoError(t, err) + + require.Equal(t, packageName, kurtosisYamlObj.PackageName) +}