Skip to content

Commit

Permalink
checkpoint on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Dec 18, 2023
1 parent 1c79ae5 commit ff3ef22
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *KurtosisHelperTestSuite) TestImportFile() {
moduleGlobalCache := map[string]*startosis_packages.ModuleCacheEntry{}

suite.packageContentProvider.EXPECT().GetModuleContents(testModuleFileName).Return("Hello World!", nil)
suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(testModulePackageId, startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil)
suite.packageContentProvider.EXPECT().GetAbsoluteLocator(testModulePackageId, startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil)

suite.run(&importModuleTestCase{
T: suite.T(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type importModuleWithLocalAbsoluteLocatorTestCase struct {
}

func (suite *KurtosisHelperTestSuite) TestImportFileWithLocalAbsoluteLocatorShouldNotBeValid() {
suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(testModulePackageId, testModuleMainFileLocator, testModuleFileName, testNoPackageReplaceOptions).Return("", startosis_errors.NewInterpretationError(importModuleWithLocalAbsoluteLocatorExpectedErrorMsg))
suite.packageContentProvider.EXPECT().GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testModuleFileName, testNoPackageReplaceOptions).Return("", startosis_errors.NewInterpretationError(importModuleWithLocalAbsoluteLocatorExpectedErrorMsg))

// start with an empty cache to validate it gets populated
moduleGlobalCache := map[string]*startosis_packages.ModuleCacheEntry{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type readFileTestCase struct {
}

func (suite *KurtosisHelperTestSuite) TestReadFile() {
suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(testModulePackageId, startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil)
suite.packageContentProvider.EXPECT().GetAbsoluteLocator(testModulePackageId, startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil)
suite.packageContentProvider.EXPECT().GetModuleContents(testModuleFileName).Return("Hello World!", nil)

suite.run(&readFileTestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type readFileWithLocalAbsoluteLocatorTestCase struct {
}

func (suite *KurtosisHelperTestSuite) TestReadFileWithLocalAbsoluteLocatorShouldNotBeValid() {
suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(testModulePackageId, testModuleMainFileLocator, testModuleFileName, testNoPackageReplaceOptions).Return("", startosis_errors.NewInterpretationError(readFileWithLocalAbsoluteLocatorExpectedErrorMsg))
suite.packageContentProvider.EXPECT().GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testModuleFileName, testNoPackageReplaceOptions).Return("", startosis_errors.NewInterpretationError(readFileWithLocalAbsoluteLocatorExpectedErrorMsg))

suite.runShouldFail(
testModuleMainFileLocator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"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/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/stretchr/testify/require"
"net"
"testing"
Expand All @@ -16,7 +16,7 @@ import (
type serviceConfigFullTestCaseBackwardCompatible struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
}

func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigFullBackwardCompatible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types/directory"
"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_constants"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/stretchr/testify/require"
"net"
"testing"
Expand All @@ -19,7 +19,7 @@ import (
type serviceConfigFullTestCase struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
}

func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigFull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,37 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"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/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/stretchr/testify/require"
"testing"
)

type serviceConfigImageBuildSpecTestCase struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
}

func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigWithImageBuildSpec() {
// setup package content provider
suite.serviceNetwork.EXPECT()
suite.packageContentProvider.EXPECT().
GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testBuildContextDir, testNoPackageReplaceOptions).
Times(1).
Return(testModuleMainFileLocator, nil)

// mock
// packageContentProvider.GetAbsoluteLocator(packageId, locatorOfModuleInWhichThisBuiltInIsBeingCalled, buildContextLocator, packageReplaceOptions)
suite.packageContentProvider.EXPECT().
GetOnDiskAbsoluteFilePath(testContainerImageLocator).
Times(1).
Return(testOnDiskContainerImagePath, nil)

// mock
// packageContentProvider.GetOnDiskAbsoluteFilePath(containerImageAbsoluteLocator)

suite.run(&serviceConfigMinimalTestCase{
suite.run(&serviceConfigImageBuildSpecTestCase{
T: suite.T(),
serviceNetwork: suite.serviceNetwork,
packageContentProvider: suite.packageContentProvider,
})
}

func (t *serviceConfigImageBuildSpecTestCase) GetStarlarkCode() string {
imageBuildSpec := fmt.Sprintf("%s(%s=%s,%s=%s,%s=%s)",
imageBuildSpec := fmt.Sprintf("%s(%s=%q,%s=%q,%s=%q)",
service_config.ImageBuildSpecTypeName,
service_config.BuiltImageNameAttr,
testContainerImageName,
Expand Down Expand Up @@ -85,4 +86,5 @@ func (t *serviceConfigImageBuildSpecTestCase) Assert(typeValue builtin_argument.
)
require.NoError(t, err)
require.Equal(t, expectedServiceConfig, serviceConfig)
require.Equal(t, expectedImageBuildSpec, serviceConfig.GetImageBuildSpec())
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"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/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/stretchr/testify/require"
"testing"
)

type serviceConfigMinimalTestCase struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
}

func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigMinimal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ var (
testContainerImageName = "kurtosistech/example-datastore-server"
testBuildContextDir = "./"
testTargetStage = "builder"
testOnDiskContextDirPath = ""
testOnDiskContainerImagePath = ""
testContainerImageLocator = "github.com/kurtosistech/test-package/Dockerfile"
testOnDiskContextDirPath = "kurtosis-data/test-package"
testOnDiskContainerImagePath = "kurtosis-data/test-package/Dockerfile"

testPrivatePortId = "grpc"
testPrivatePortNumber = uint16(1323)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/runtime_value_store"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_constants"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/stretchr/testify/suite"
"go.starlark.net/starlark"
"reflect"
Expand All @@ -25,7 +25,7 @@ type KurtosisTypeConstructorTestSuite struct {

serviceNetwork *service_network.MockServiceNetwork
runtimeValueStore *runtime_value_store.RuntimeValueStore
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
}

func TestKurtosisTypeConstructorSuite(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func (suite *KurtosisTypeConstructorTestSuite) SetupTest() {
suite.Require().NoError(err)
suite.runtimeValueStore = runtimeValueStoreForTest

suite.packageContentProvider = mock_package_content_provider.NewMockPackageContentProvider()
suite.packageContentProvider = startosis_packages.NewMockPackageContentProvider(suite.T())
}

func (suite *KurtosisTypeConstructorTestSuite) run(builtin KurtosisTypeConstructorBaseTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/kurtosis_plan_instruction"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/kurtosis-tech/kurtosis/core/server/commons/enclave_data_directory"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -16,7 +16,7 @@ import (
type uploadFilesTestCase struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider startosis_packages.PackageContentProvider
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
}

func (suite *KurtosisPlanInstructionTestSuite) TestUploadFiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/service_network"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/kurtosis_plan_instruction"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.starlark.net/starlark"
Expand All @@ -15,7 +15,7 @@ import (
type uploadFilesUpdateTestCase struct {
*testing.T
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider startosis_packages.PackageContentProvider
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
}

func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,30 +579,30 @@ func convertFilesArguments(attrNameForLogging string, filesDict *starlark.Dict)
return filesArtifacts, persistentDirectories, nil
}

// If [rawImageAttrValue] is a string, returns the image name with no image build spec (image will be fetched from local cache or remote)
// If [rawImageAttrValue] is an ImageBuildSpec type, returns name for the image to build and ImageBuildSpec converted to KurtosisType
// If [rawImageAttrValue] is a string, returns the image name with no image build spec (image will be fetched from local cache or remote)
func convertImageAttr(
rawImageAttrValue starlark.Value,
locatorOfModuleInWhichThisBuiltInIsBeingCalled string,
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string) (string, *image_build_spec.ImageBuildSpec, *startosis_errors.InterpretationError) {
imageName, interpretationErr := kurtosis_types.SafeCastToString(rawImageAttrValue, ImageAttr)
if interpretationErr == nil {
return imageName, nil, nil
} else {
imageBuildSpecStarlarkType, isImageBuildSpecStarlarkType := rawImageAttrValue.(*ImageBuildSpec)
if !isImageBuildSpecStarlarkType {
return "", nil, startosis_errors.NewInterpretationError("Failed to cast '%v' to an image build spec object.", rawImageAttrValue)
}
imageBuildSpecStarlarkType, isImageBuildSpecStarlarkType := rawImageAttrValue.(*ImageBuildSpec)
if isImageBuildSpecStarlarkType {
imageBuildSpec, interpretationErr := imageBuildSpecStarlarkType.ToKurtosisType(locatorOfModuleInWhichThisBuiltInIsBeingCalled, packageId, packageContentProvider, packageReplaceOptions)
if interpretationErr != nil {
return "", nil, interpretationErr
}
imageName, interpretationErr = imageBuildSpecStarlarkType.GetImageName()
imageName, interpretationErr := imageBuildSpecStarlarkType.GetImageName()
if interpretationErr != nil {
return "", nil, interpretationErr
}
return imageName, imageBuildSpec, nil
} else {
imageName, interpretationErr := kurtosis_types.SafeCastToString(rawImageAttrValue, ImageAttr)
if interpretationErr != nil {
return "", nil, interpretationErr
}
return imageName, nil, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_types/port_spec"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/runtime_value_store"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_constants"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.starlark.net/starlark"
Expand All @@ -34,12 +33,12 @@ var noPackageReplaceOptions = map[string]string{}

type StartosisInterpreterIdempotentTestSuite struct {
suite.Suite
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
interpreter *StartosisInterpreter
}

func (suite *StartosisInterpreterIdempotentTestSuite) SetupTest() {
suite.packageContentProvider = mock_package_content_provider.NewMockPackageContentProvider()
suite.packageContentProvider = startosis_packages.NewMockPackageContentProvider(suite.T())
enclaveDb := getEnclaveDBForTest(suite.T())

thread := &starlark.Thread{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/runtime_value_store"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_constants"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"net"
Expand Down Expand Up @@ -54,14 +53,14 @@ const (
type StartosisInterpreterTestSuite struct {
suite.Suite
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
packageContentProvider *startosis_packages.MockPackageContentProvider
runtimeValueStore *runtime_value_store.RuntimeValueStore

interpreter *StartosisInterpreter
}

func (suite *StartosisInterpreterTestSuite) SetupTest() {
suite.packageContentProvider = mock_package_content_provider.NewMockPackageContentProvider()
suite.packageContentProvider = startosis_packages.NewMockPackageContentProvider(suite.T())
enclaveDb := getEnclaveDBForTest(suite.T())

dummySerde := shared_helpers.NewDummyStarlarkValueSerDeForTest()
Expand Down
Loading

0 comments on commit ff3ef22

Please sign in to comment.