Skip to content

Commit

Permalink
finish apic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Dec 19, 2023
1 parent ff3ef22 commit 0e01918
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (

ServiceNameArgName = "name"
ServiceConfigArgName = "config"

testRootModuleLocator = "./"
)

func NewAddService(
Expand All @@ -50,19 +52,20 @@ func NewAddService(
Name: ServiceConfigArgName,
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[*service_config.ServiceConfig],
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
// we just try to convert the configs here to validate their shape, to avoid code duplication with Interpret
if _, _, err := validateAndConvertConfigAndReadyCondition(
serviceNetwork,
value,
"",
packageId,
packageContentProvider,
packageReplaceOptions); err != nil {
return err
}
return nil
},
Validator: nil,
//Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
// // we just try to convert the configs here to validate their shape, to avoid code duplication with Interpret
// if _, _, err := validateAndConvertConfigAndReadyCondition(
// serviceNetwork,
// value,
// packageId, // use package id for root locator
// packageId,
// packageContentProvider,
// packageReplaceOptions); err != nil {
// return err
// }
// return nil
//},
},
},
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
package test_engine

import (
"fmt"
"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"
"testing"
)

type imageBuildSpecTest struct {
*testing.T

packageContentProvider *startosis_packages.MockPackageContentProvider
}

func (suite *KurtosisTypeConstructorTestSuite) TestImageBuildSpecTest() {
suite.packageContentProvider.EXPECT().
GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testBuildContextDir, testNoPackageReplaceOptions).
Times(1).
Return(testBuildContextLocator, nil)

suite.packageContentProvider.EXPECT().
GetOnDiskAbsoluteFilePath(testContainerImageLocator).
Times(1).
Return(testOnDiskContainerImagePath, nil)

suite.run(&imageBuildSpecTest{
T: suite.T(),
packageContentProvider: suite.packageContentProvider,
})
}

func (t *imageBuildSpecTest) GetStarlarkCode() string {
return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q)",
service_config.ImageBuildSpecTypeName,
service_config.BuiltImageNameAttr,
testContainerImageName,
service_config.BuildContextAttr,
testBuildContextDir,
service_config.TargetStageAttr,
testTargetStage)
}

func (t *imageBuildSpecTest) 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, testOnDiskContainerImagePath, imageBuildSpec.GetContainerImageFilePath())
require.Equal(t, testOnDiskContextDirPath, imageBuildSpec.GetContextDirPath())
require.Equal(t, testTargetStage, imageBuildSpec.GetTargetStage())
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigWithImageBuildSp
suite.packageContentProvider.EXPECT().
GetAbsoluteLocator(testModulePackageId, testModuleMainFileLocator, testBuildContextDir, testNoPackageReplaceOptions).
Times(1).
Return(testModuleMainFileLocator, nil)
Return(testBuildContextLocator, nil)

suite.packageContentProvider.EXPECT().
GetOnDiskAbsoluteFilePath(testContainerImageLocator).
Expand All @@ -38,15 +38,15 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigWithImageBuildSp
}

func (t *serviceConfigImageBuildSpecTestCase) GetStarlarkCode() string {
imageBuildSpec := fmt.Sprintf("%s(%s=%q,%s=%q,%s=%q)",
imageBuildSpec := fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q)",
service_config.ImageBuildSpecTypeName,
service_config.BuiltImageNameAttr,
testContainerImageName,
service_config.BuildContextAttr,
testBuildContextDir,
service_config.TargetStageAttr,
testTargetStage)
return fmt.Sprintf("%s(%s=%q)",
return fmt.Sprintf("%s(%s=%s)",
service_config.ServiceConfigTypeName,
service_config.ImageAttr, imageBuildSpec)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
testContainerImageName = "kurtosistech/example-datastore-server"
testBuildContextDir = "./"
testTargetStage = "builder"
testBuildContextLocator = testModulePackageId
testContainerImageLocator = "github.com/kurtosistech/test-package/Dockerfile"
testOnDiskContextDirPath = "kurtosis-data/test-package"
testOnDiskContainerImagePath = "kurtosis-data/test-package/Dockerfile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/starlark_warning"
"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"
"github.com/sirupsen/logrus"
"go.starlark.net/starlark"
"math"
"path"
Expand Down Expand Up @@ -597,6 +598,7 @@ func convertImageAttr(
if interpretationErr != nil {
return "", nil, interpretationErr
}
logrus.Debugf("CONVERT IMAGE ATTRIBUTE: %v %v", imageName, imageBuildSpec)
return imageName, imageBuildSpec, nil
} else {
imageName, interpretationErr := kurtosis_types.SafeCastToString(rawImageAttrValue, ImageAttr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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 @@ -33,12 +34,12 @@ var noPackageReplaceOptions = map[string]string{}

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

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

thread := &starlark.Thread{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -53,14 +54,14 @@ const (
type StartosisInterpreterTestSuite struct {
suite.Suite
serviceNetwork *service_network.MockServiceNetwork
packageContentProvider *startosis_packages.MockPackageContentProvider
packageContentProvider *mock_package_content_provider.MockPackageContentProvider
runtimeValueStore *runtime_value_store.RuntimeValueStore

interpreter *StartosisInterpreter
}

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

dummySerde := shared_helpers.NewDummyStarlarkValueSerDeForTest()
Expand Down

0 comments on commit 0e01918

Please sign in to comment.