Skip to content

Commit

Permalink
test: add custom build file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Feb 27, 2024
1 parent 41eb447 commit b96c467
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b96c467

Please sign in to comment.