From b96c467821d44030d15d81aba5a4ad2904bde311 Mon Sep 17 00:00:00 2001 From: leovct Date: Tue, 27 Feb 2024 09:35:14 +0100 Subject: [PATCH] test: add custom build file tests --- ...d_spec_framework_with_custom_build_file.go | 62 +++++++++++++++++++ .../test_engine/static_constants.go | 19 +++--- 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/image_build_spec_framework_with_custom_build_file.go diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/image_build_spec_framework_with_custom_build_file.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/image_build_spec_framework_with_custom_build_file.go new file mode 100644 index 0000000000..4feb77db82 --- /dev/null +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/image_build_spec_framework_with_custom_build_file.go @@ -0,0 +1,62 @@ +package test_engine + +import ( + "fmt" + "testing" + + "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/builtin_argument" + "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types/service_config" + "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages" + "github.com/stretchr/testify/require" +) + +type imageBuildSpecWithCustomBuildFileTest struct { + *testing.T + + packageContentProvider *startosis_packages.MockPackageContentProvider +} + +func (suite *KurtosisTypeConstructorTestSuite) TestImageBuildSpecTestWithCustomBuildFile() { + suite.packageContentProvider.EXPECT(). + GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testBuildContextDir, testNoPackageReplaceOptions). + Times(1). + Return(testBuildContextLocator, nil) + + suite.packageContentProvider.EXPECT(). + GetOnDiskAbsolutePackageFilePath(testContainerImageCustomLocator). + Times(1). + Return(testOnDiskContainerImageCustomPath, nil) + + suite.run(&imageBuildSpecWithCustomBuildFileTest{ + T: suite.T(), + packageContentProvider: suite.packageContentProvider, + }) +} + +func (t *imageBuildSpecWithCustomBuildFileTest) GetStarlarkCode() string { + return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%q)", + service_config.ImageBuildSpecTypeName, + service_config.BuiltImageNameAttr, + testContainerImageName, + service_config.BuildContextAttr, + testBuildContextDir, + service_config.BuildFileAttr, + testCustomBuildFile, + service_config.TargetStageAttr, + testTargetStage) +} + +func (t *imageBuildSpecWithCustomBuildFileTest) Assert(typeValue builtin_argument.KurtosisValueType) { + imageBuildSpecStarlark, ok := typeValue.(*service_config.ImageBuildSpec) + require.True(t, ok) + + imageBuildSpec, err := imageBuildSpecStarlark.ToKurtosisType( + testModuleMainFileLocator, + testModulePackageId, + t.packageContentProvider, + testNoPackageReplaceOptions) + require.Nil(t, err) + require.Equal(t, testOnDiskContainerCustomImagePath, imageBuildSpec.GetContainerImageFilePath()) + require.Equal(t, testOnDiskContextDirPath, imageBuildSpec.GetBuildContextDir()) + require.Equal(t, testTargetStage, imageBuildSpec.GetTargetStage()) +} diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go index d503fa44b0..ced741cdc6 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/static_constants.go @@ -26,14 +26,17 @@ var ( testModuleFileName = "github.com/kurtosistech/test-package/helpers.star" testModuleRelativeLocator = "./helpers.star" - testContainerImageName = "kurtosistech/example-datastore-server" - testBuildContextDir = "./" - testBuildFile = "" - testTargetStage = "builder" - testBuildContextLocator = testModulePackageId - testContainerImageLocator = "github.com/kurtosistech/test-package/Dockerfile" - testOnDiskContextDirPath = "kurtosis-data/test-package" - testOnDiskContainerImagePath = "kurtosis-data/test-package/Dockerfile" + testContainerImageName = "kurtosistech/example-datastore-server" + testBuildContextDir = "./" + testBuildFile = "" + testCustomBuildFile = "foo.Dockerfile" + testTargetStage = "builder" + testBuildContextLocator = testModulePackageId + testContainerImageLocator = "github.com/kurtosistech/test-package/Dockerfile" + testContainerImageCustomLocator = "github.com/kurtosistech/test-package/foo.Dockerfile" + testOnDiskContextDirPath = "kurtosis-data/test-package" + testOnDiskContainerImagePath = "kurtosis-data/test-package/Dockerfile" + testOnDiskContainerImageCustomPath = "kurtosis-data/test-package/foo.Dockerfile" testNixContextDir = "./" testNixImageName = "test-image"