diff --git a/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go b/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go index 618976c02a..ae3da39081 100644 --- a/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go +++ b/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc-gen-go v1.30.0 +// protoc v4.23.2 // source: api_container_service.proto package kurtosis_core_rpc_api_bindings diff --git a/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service_grpc.pb.go b/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service_grpc.pb.go index d301aa958a..e8920314b8 100644 --- a/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service_grpc.pb.go +++ b/api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.23.4 +// - protoc v4.23.2 // source: api_container_service.proto package kurtosis_core_rpc_api_bindings diff --git a/api/golang/core/lib/enclaves/enclave_context.go b/api/golang/core/lib/enclaves/enclave_context.go index 588c9d89cf..b9b89cac7c 100644 --- a/api/golang/core/lib/enclaves/enclave_context.go +++ b/api/golang/core/lib/enclaves/enclave_context.go @@ -125,7 +125,7 @@ func (enclaveCtx *EnclaveContext) RunStarlarkPackage( ) (chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) { serializedParams, err := maybeParseYaml(runConfig.SerializedParams) if err != nil { - return nil, nil, stacktrace.Propagate(err, "An error occured when parsing YAML args for package '%v'", serializedParams) + return nil, nil, stacktrace.Propagate(err, "An error occurred when parsing YAML args for package '%v'", serializedParams) } executionStartedSuccessfully := false ctxWithCancel, cancelCtxFunc := context.WithCancel(ctx) @@ -193,7 +193,7 @@ func (enclaveCtx *EnclaveContext) RunStarlarkRemotePackage( ) (chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) { serializedParams, err := maybeParseYaml(runConfig.SerializedParams) if err != nil { - return nil, nil, stacktrace.Propagate(err, "An error occured when parsing YAML args for remote package '%v'", serializedParams) + return nil, nil, stacktrace.Propagate(err, "An error occurred when parsing YAML args for remote package '%v'", serializedParams) } executionStartedSuccessfully := false ctxWithCancel, cancelCtxFunc := context.WithCancel(ctx) diff --git a/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service.pb.go b/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service.pb.go index b8c245a5c0..360a81e0cf 100644 --- a/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service.pb.go +++ b/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc-gen-go v1.30.0 +// protoc v4.23.2 // source: engine_service.proto package kurtosis_engine_rpc_api_bindings diff --git a/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service_grpc.pb.go b/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service_grpc.pb.go index 62d8e61495..653f1c2702 100644 --- a/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service_grpc.pb.go +++ b/api/golang/engine/kurtosis_engine_rpc_api_bindings/engine_service_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.23.4 +// - protoc v4.23.2 // source: engine_service.proto package kurtosis_engine_rpc_api_bindings diff --git a/api/protobuf/core/api_container_service.proto b/api/protobuf/core/api_container_service.proto index cb506d031e..1020827e6f 100644 --- a/api/protobuf/core/api_container_service.proto +++ b/api/protobuf/core/api_container_service.proto @@ -47,7 +47,7 @@ service ApiContainerService { rpc ListFilesArtifactNamesAndUuids(google.protobuf.Empty) returns (ListFilesArtifactNamesAndUuidsResponse) {} rpc InspectFilesArtifactContents(InspectFilesArtifactContentsRequest) returns (InspectFilesArtifactContentsResponse) {} - + // User services port forwarding rpc ConnectServices(ConnectServicesArgs) returns (ConnectServicesResponse) {}; diff --git a/cli/cli/commands/run/run.go b/cli/cli/commands/run/run.go index 319eabc17c..bea458b960 100644 --- a/cli/cli/commands/run/run.go +++ b/cli/cli/commands/run/run.go @@ -490,11 +490,11 @@ func executePackage( ) (<-chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine, context.CancelFunc, error) { // we get the absolute path so that the logs make more sense absolutePackagePath, err := filepath.Abs(packagePath) - logrus.Infof("Executing Starlark package at '%v' as the passed argument '%v' looks like a directory", absolutePackagePath, packagePath) - if err != nil { return nil, nil, stacktrace.Propagate(err, "An error occurred while getting the absolute path for '%v'", packagePath) } + logrus.Infof("Executing Starlark package at '%v' as the passed argument '%v' looks like a directory", absolutePackagePath, packagePath) + return enclaveCtx.RunStarlarkPackage(ctx, packagePath, runConfig) } diff --git a/core/server/api_container/server/api_container_service.go b/core/server/api_container/server/api_container_service.go index d82e98a173..93a588e165 100644 --- a/core/server/api_container/server/api_container_service.go +++ b/core/server/api_container/server/api_container_service.go @@ -12,6 +12,8 @@ import ( "compress/gzip" "context" "fmt" + "github.com/kurtosis-tech/kurtosis/core/server/commons/yaml_parser" + metrics_client "github.com/kurtosis-tech/metrics-library/golang/lib/client" "io" "math" "net/http" @@ -21,8 +23,6 @@ import ( "time" "unicode" - metrics_client "github.com/kurtosis-tech/metrics-library/golang/lib/client" - "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/uuid_generator" "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" @@ -138,7 +138,9 @@ func (apicService *ApiContainerService) RunStarlarkScript(args *kurtosis_core_rp if metricsErr != nil { logrus.Warn("An error occurred tracking kurtosis run event") } - apicService.runStarlark(parallelism, dryRun, startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFuncName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, serializedStarlarkScript, serializedParams, args.GetExperimentalFeatures(), stream) + noPackageReplaceOptions := map[string]string{} + + apicService.runStarlark(parallelism, dryRun, startosis_constants.PackageIdPlaceholderForStandaloneScript, noPackageReplaceOptions, mainFuncName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, serializedStarlarkScript, serializedParams, args.GetExperimentalFeatures(), stream) apicService.starlarkRun = &kurtosis_core_rpc_api_bindings.GetStarlarkRunResponse{ PackageId: startosis_constants.PackageIdPlaceholderForStandaloneScript, @@ -154,7 +156,7 @@ func (apicService *ApiContainerService) RunStarlarkScript(args *kurtosis_core_rp return nil } -func (apicService ApiContainerService) UploadStarlarkPackage(server kurtosis_core_rpc_api_bindings.ApiContainerService_UploadStarlarkPackageServer) error { +func (apicService *ApiContainerService) UploadStarlarkPackage(server kurtosis_core_rpc_api_bindings.ApiContainerService_UploadStarlarkPackageServer) error { var packageId string serverStream := grpc_file_streaming.NewServerStream[kurtosis_core_rpc_api_bindings.StreamedDataChunk, emptypb.Empty](server) @@ -188,7 +190,7 @@ func (apicService ApiContainerService) UploadStarlarkPackage(server kurtosis_cor return nil } -func (apicService ApiContainerService) InspectFilesArtifactContents(_ context.Context, args *kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsRequest) (*kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsResponse, error) { +func (apicService *ApiContainerService) InspectFilesArtifactContents(_ context.Context, args *kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsRequest) (*kurtosis_core_rpc_api_bindings.InspectFilesArtifactContentsResponse, error) { artifactIdentifier := "" if args.GetFileNamesAndUuid().GetFileUuid() != emptyFileArtifactIdentifier { artifactIdentifier = args.GetFileNamesAndUuid().GetFileUuid() @@ -236,16 +238,16 @@ func (apicService *ApiContainerService) RunStarlarkPackage(args *kurtosis_core_r // right now the TS SDK still uses the old deprecated behavior var scriptWithRunFunction string var interpretationError *startosis_errors.InterpretationError - var packageName string var isRemote bool + var kurtosisYml *yaml_parser.KurtosisYaml if args.ClonePackage != nil { - scriptWithRunFunction, packageName, interpretationError = apicService.runStarlarkPackageSetup(packageId, args.GetClonePackage(), nil, relativePathToMainFile) + scriptWithRunFunction, kurtosisYml, interpretationError = apicService.runStarlarkPackageSetup(packageId, args.GetClonePackage(), nil, relativePathToMainFile) isRemote = args.GetClonePackage() } else { // old deprecated syntax in use moduleContentIfLocal := args.GetLocal() isRemote = args.GetRemote() - scriptWithRunFunction, packageName, interpretationError = apicService.runStarlarkPackageSetup(packageId, args.GetRemote(), moduleContentIfLocal, relativePathToMainFile) + scriptWithRunFunction, kurtosisYml, interpretationError = apicService.runStarlarkPackageSetup(packageId, args.GetRemote(), moduleContentIfLocal, relativePathToMainFile) } if interpretationError != nil { if err := stream.SendMsg(binding_constructors.NewStarlarkRunResponseLineFromInterpretationError(interpretationError.ToAPIType())); err != nil { @@ -253,12 +255,15 @@ func (apicService *ApiContainerService) RunStarlarkPackage(args *kurtosis_core_r } return nil } + packageName := kurtosisYml.GetPackageName() + packageReplaceOptions := kurtosisYml.GetPackageReplaceOptions() + logrus.Debugf("package replace options received '%+v'", packageReplaceOptions) metricsErr := apicService.metricsClient.TrackKurtosisRun(packageName, isRemote, dryRun, isNotScript, cloudInstanceID, cloudUserId) if metricsErr != nil { logrus.Warn("An error occurred tracking kurtosis run event") } - apicService.runStarlark(parallelism, dryRun, packageName, mainFuncName, relativePathToMainFile, scriptWithRunFunction, serializedParams, args.ExperimentalFeatures, stream) + apicService.runStarlark(parallelism, dryRun, packageName, packageReplaceOptions, mainFuncName, relativePathToMainFile, scriptWithRunFunction, serializedParams, args.ExperimentalFeatures, stream) apicService.starlarkRun = &kurtosis_core_rpc_api_bindings.GetStarlarkRunResponse{ PackageId: packageId, @@ -270,11 +275,10 @@ func (apicService *ApiContainerService) RunStarlarkPackage(args *kurtosis_core_r ExperimentalFeatures: args.ExperimentalFeatures, RestartPolicy: apicService.restartPolicy, } - return nil } -func (apicService ApiContainerService) ExecCommand(ctx context.Context, args *kurtosis_core_rpc_api_bindings.ExecCommandArgs) (*kurtosis_core_rpc_api_bindings.ExecCommandResponse, error) { +func (apicService *ApiContainerService) ExecCommand(ctx context.Context, args *kurtosis_core_rpc_api_bindings.ExecCommandArgs) (*kurtosis_core_rpc_api_bindings.ExecCommandResponse, error) { serviceIdentifier := args.ServiceIdentifier command := args.CommandArgs execResult, err := apicService.serviceNetwork.RunExec(ctx, serviceIdentifier, command) @@ -301,7 +305,7 @@ func (apicService ApiContainerService) ExecCommand(ctx context.Context, args *ku return resp, nil } -func (apicService ApiContainerService) WaitForHttpGetEndpointAvailability(ctx context.Context, args *kurtosis_core_rpc_api_bindings.WaitForHttpGetEndpointAvailabilityArgs) (*emptypb.Empty, error) { +func (apicService *ApiContainerService) WaitForHttpGetEndpointAvailability(ctx context.Context, args *kurtosis_core_rpc_api_bindings.WaitForHttpGetEndpointAvailabilityArgs) (*emptypb.Empty, error) { serviceIdentifier := args.ServiceIdentifier @@ -326,7 +330,7 @@ func (apicService ApiContainerService) WaitForHttpGetEndpointAvailability(ctx co return &emptypb.Empty{}, nil } -func (apicService ApiContainerService) WaitForHttpPostEndpointAvailability(ctx context.Context, args *kurtosis_core_rpc_api_bindings.WaitForHttpPostEndpointAvailabilityArgs) (*emptypb.Empty, error) { +func (apicService *ApiContainerService) WaitForHttpPostEndpointAvailability(ctx context.Context, args *kurtosis_core_rpc_api_bindings.WaitForHttpPostEndpointAvailabilityArgs) (*emptypb.Empty, error) { serviceIdentifier := args.ServiceIdentifier if err := apicService.waitForEndpointAvailability( @@ -350,7 +354,7 @@ func (apicService ApiContainerService) WaitForHttpPostEndpointAvailability(ctx c return &emptypb.Empty{}, nil } -func (apicService ApiContainerService) GetServices(ctx context.Context, args *kurtosis_core_rpc_api_bindings.GetServicesArgs) (*kurtosis_core_rpc_api_bindings.GetServicesResponse, error) { +func (apicService *ApiContainerService) GetServices(ctx context.Context, args *kurtosis_core_rpc_api_bindings.GetServicesArgs) (*kurtosis_core_rpc_api_bindings.GetServicesResponse, error) { serviceInfos := map[string]*kurtosis_core_rpc_api_bindings.ServiceInfo{} filterServiceIdentifiers := args.ServiceIdentifiers @@ -382,12 +386,12 @@ func (apicService ApiContainerService) GetServices(ctx context.Context, args *ku return resp, nil } -func (apicService ApiContainerService) ConnectServices(ctx context.Context, args *kurtosis_core_rpc_api_bindings.ConnectServicesArgs) (*kurtosis_core_rpc_api_bindings.ConnectServicesResponse, error) { +func (apicService *ApiContainerService) ConnectServices(_ context.Context, _ *kurtosis_core_rpc_api_bindings.ConnectServicesArgs) (*kurtosis_core_rpc_api_bindings.ConnectServicesResponse, error) { resp := binding_constructors.NewConnectServicesResponse() return resp, nil } -func (apicService ApiContainerService) GetExistingAndHistoricalServiceIdentifiers(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.GetExistingAndHistoricalServiceIdentifiersResponse, error) { +func (apicService *ApiContainerService) GetExistingAndHistoricalServiceIdentifiers(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.GetExistingAndHistoricalServiceIdentifiersResponse, error) { allIdentifiers, err := apicService.serviceNetwork.GetExistingAndHistoricalServiceIdentifiers() if err != nil { return nil, stacktrace.Propagate(err, "An error occurred getting existing and historical service identifiers") @@ -409,7 +413,7 @@ func (apicService ApiContainerService) GetExistingAndHistoricalServiceIdentifier return existingAndHistoricalServiceIdentifiersResponse, nil } -func (apicService ApiContainerService) UploadFilesArtifact(server kurtosis_core_rpc_api_bindings.ApiContainerService_UploadFilesArtifactServer) error { +func (apicService *ApiContainerService) UploadFilesArtifact(server kurtosis_core_rpc_api_bindings.ApiContainerService_UploadFilesArtifactServer) error { var maybeArtifactName string serverStream := grpc_file_streaming.NewServerStream[kurtosis_core_rpc_api_bindings.StreamedDataChunk, kurtosis_core_rpc_api_bindings.UploadFilesArtifactResponse](server) @@ -445,7 +449,7 @@ func (apicService ApiContainerService) UploadFilesArtifact(server kurtosis_core_ return nil } -func (apicService ApiContainerService) DownloadFilesArtifact(args *kurtosis_core_rpc_api_bindings.DownloadFilesArtifactArgs, server kurtosis_core_rpc_api_bindings.ApiContainerService_DownloadFilesArtifactServer) error { +func (apicService *ApiContainerService) DownloadFilesArtifact(args *kurtosis_core_rpc_api_bindings.DownloadFilesArtifactArgs, server kurtosis_core_rpc_api_bindings.ApiContainerService_DownloadFilesArtifactServer) error { artifactIdentifier := args.Identifier if strings.TrimSpace(artifactIdentifier) == "" { return stacktrace.NewError("Cannot download file with empty files artifact identifier") @@ -500,7 +504,7 @@ func (apicService ApiContainerService) DownloadFilesArtifact(args *kurtosis_core return nil } -func (apicService ApiContainerService) StoreWebFilesArtifact(ctx context.Context, args *kurtosis_core_rpc_api_bindings.StoreWebFilesArtifactArgs) (*kurtosis_core_rpc_api_bindings.StoreWebFilesArtifactResponse, error) { +func (apicService *ApiContainerService) StoreWebFilesArtifact(_ context.Context, args *kurtosis_core_rpc_api_bindings.StoreWebFilesArtifactArgs) (*kurtosis_core_rpc_api_bindings.StoreWebFilesArtifactResponse, error) { url := args.Url artifactName := args.Name @@ -522,7 +526,7 @@ func (apicService ApiContainerService) StoreWebFilesArtifact(ctx context.Context return response, nil } -func (apicService ApiContainerService) StoreFilesArtifactFromService(ctx context.Context, args *kurtosis_core_rpc_api_bindings.StoreFilesArtifactFromServiceArgs) (*kurtosis_core_rpc_api_bindings.StoreFilesArtifactFromServiceResponse, error) { +func (apicService *ApiContainerService) StoreFilesArtifactFromService(ctx context.Context, args *kurtosis_core_rpc_api_bindings.StoreFilesArtifactFromServiceArgs) (*kurtosis_core_rpc_api_bindings.StoreFilesArtifactFromServiceResponse, error) { serviceIdentifier := args.ServiceIdentifier srcPath := args.SourcePath name := args.Name @@ -536,7 +540,7 @@ func (apicService ApiContainerService) StoreFilesArtifactFromService(ctx context return response, nil } -func (apicService ApiContainerService) ListFilesArtifactNamesAndUuids(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.ListFilesArtifactNamesAndUuidsResponse, error) { +func (apicService *ApiContainerService) ListFilesArtifactNamesAndUuids(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.ListFilesArtifactNamesAndUuidsResponse, error) { filesArtifactsNamesAndUuids := apicService.filesArtifactStore.GetFileNamesAndUuids() var filesArtifactNamesAndUuids []*kurtosis_core_rpc_api_bindings.FilesArtifactNameAndUuid for _, nameAndUuid := range filesArtifactsNamesAndUuids { @@ -549,7 +553,7 @@ func (apicService ApiContainerService) ListFilesArtifactNamesAndUuids(_ context. return &kurtosis_core_rpc_api_bindings.ListFilesArtifactNamesAndUuidsResponse{FileNamesAndUuids: filesArtifactNamesAndUuids}, nil } -func (apicService ApiContainerService) GetStarlarkRun(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.GetStarlarkRunResponse, error) { +func (apicService *ApiContainerService) GetStarlarkRun(_ context.Context, _ *emptypb.Empty) (*kurtosis_core_rpc_api_bindings.GetStarlarkRunResponse, error) { return apicService.starlarkRun, nil } @@ -562,7 +566,7 @@ func transformPortSpecToApiPort(port *port_spec.PortSpec) (*kurtosis_core_rpc_ap portNumUint16 := port.GetNumber() portSpecProto := port.GetTransportProtocol() - // Yes, this isn't the most efficient way to do this, but the map is tiny so it doesn't matter + // Yes, this isn't the most efficient way to do this, but the map is tiny, so it doesn't matter var apiProto kurtosis_core_rpc_api_bindings.Port_TransportProtocol foundApiProto := false for mappedApiProto, mappedPortSpecProto := range apiContainerPortProtoToPortSpecPortProto { @@ -602,7 +606,7 @@ func transformPortSpecMapToApiPortsMap(apiPorts map[string]*port_spec.PortSpec) return result, nil } -func (apicService ApiContainerService) waitForEndpointAvailability( +func (apicService *ApiContainerService) waitForEndpointAvailability( ctx context.Context, serviceIdStr string, httpMethod string, @@ -698,7 +702,7 @@ func makeHttpRequest(httpMethod string, url string, body string) (*http.Response return resp, nil } -func (apicService ApiContainerService) getServiceInfoForIdentifier(ctx context.Context, serviceIdentifier string) (*kurtosis_core_rpc_api_bindings.ServiceInfo, error) { +func (apicService *ApiContainerService) getServiceInfoForIdentifier(ctx context.Context, serviceIdentifier string) (*kurtosis_core_rpc_api_bindings.ServiceInfo, error) { serviceObj, err := apicService.serviceNetwork.GetService( ctx, serviceIdentifier, @@ -713,50 +717,55 @@ func (apicService ApiContainerService) getServiceInfoForIdentifier(ctx context.C return serviceInfo, nil } -func (apicService ApiContainerService) runStarlarkPackageSetup( +func (apicService *ApiContainerService) runStarlarkPackageSetup( packageId string, clonePackage bool, moduleContentIfLocal []byte, relativePathToMainFile string, -) (string, string, *startosis_errors.InterpretationError) { +) (string, *yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError) { var packageRootPathOnDisk string var interpretationError *startosis_errors.InterpretationError - var packageName string + if clonePackage { - packageRootPathOnDisk, packageName, interpretationError = apicService.startosisModuleContentProvider.ClonePackage(packageId) + packageRootPathOnDisk, interpretationError = apicService.startosisModuleContentProvider.ClonePackage(packageId) } else if moduleContentIfLocal != nil { // TODO: remove this once UploadStarlarkPackage is called prior to calling RunStarlarkPackage by all consumers // of this API packageRootPathOnDisk, interpretationError = apicService.startosisModuleContentProvider.StorePackageContents(packageId, bytes.NewReader(moduleContentIfLocal), doOverwriteExistingModule) - packageName = packageId } else { // We just need to retrieve the absolute path, the content is will not be stored here since it has been uploaded // prior to this call packageRootPathOnDisk, interpretationError = apicService.startosisModuleContentProvider.GetOnDiskAbsolutePackagePath(packageId) - packageName = packageId + } if interpretationError != nil { - return "", "", interpretationError + return "", nil, interpretationError + } + + kurtosisYml, interpretationError := apicService.startosisModuleContentProvider.GetKurtosisYaml(packageRootPathOnDisk) + if interpretationError != nil { + return "", nil, interpretationError } pathToMainFile := path.Join(packageRootPathOnDisk, relativePathToMainFile) if _, err := os.Stat(pathToMainFile); err != nil { - return "", "", startosis_errors.WrapWithInterpretationError(err, "An error occurred while verifying that '%v' exists in the package '%v' at '%v'", startosis_constants.MainFileName, packageId, pathToMainFile) + return "", nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while verifying that '%v' exists in the package '%v' at '%v'", startosis_constants.MainFileName, packageId, pathToMainFile) } mainScriptToExecute, err := os.ReadFile(pathToMainFile) if err != nil { - return "", "", startosis_errors.WrapWithInterpretationError(err, "An error occurred while reading '%v' in the package '%v' at '%v'", startosis_constants.MainFileName, packageId, pathToMainFile) + return "", nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while reading '%v' in the package '%v' at '%v'", startosis_constants.MainFileName, packageId, pathToMainFile) } - return string(mainScriptToExecute), packageName, nil + return string(mainScriptToExecute), kurtosisYml, nil } -func (apicService ApiContainerService) runStarlark( +func (apicService *ApiContainerService) runStarlark( parallelism int, dryRun bool, packageId string, + packageReplaceOptions map[string]string, mainFunctionName string, relativePathToMainFile string, serializedStarlark string, @@ -764,7 +773,7 @@ func (apicService ApiContainerService) runStarlark( experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag, stream grpc.ServerStream, ) { - responseLineStream := apicService.startosisRunner.Run(stream.Context(), dryRun, parallelism, packageId, mainFunctionName, relativePathToMainFile, serializedStarlark, serializedParams, experimentalFeatures) + responseLineStream := apicService.startosisRunner.Run(stream.Context(), dryRun, parallelism, packageId, packageReplaceOptions, mainFunctionName, relativePathToMainFile, serializedStarlark, serializedParams, experimentalFeatures) for { select { case <-stream.Context().Done(): diff --git a/core/server/api_container/server/startosis_engine/builtins/import_module/import_module.go b/core/server/api_container/server/startosis_engine/builtins/import_module/import_module.go index d38872bc16..83f4bac05f 100644 --- a/core/server/api_container/server/startosis_engine/builtins/import_module/import_module.go +++ b/core/server/api_container/server/startosis_engine/builtins/import_module/import_module.go @@ -6,6 +6,7 @@ import ( "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/kurtosis_helper" "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" "go.starlark.net/starlarkstruct" ) @@ -36,6 +37,7 @@ func NewImportModule( recursiveInterpret func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError), packageContentProvider startosis_packages.PackageContentProvider, moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry, + packageReplaceOptions map[string]string, ) *kurtosis_helper.KurtosisHelper { return &kurtosis_helper.KurtosisHelper{ KurtosisBaseBuiltin: &kurtosis_starlark_framework.KurtosisBaseBuiltin{ @@ -56,6 +58,7 @@ func NewImportModule( packageContentProvider: packageContentProvider, recursiveInterpret: recursiveInterpret, moduleGlobalCache: moduleGlobalCache, + packageReplaceOptions: packageReplaceOptions, }, } } @@ -64,21 +67,23 @@ type importModuleCapabilities struct { packageContentProvider startosis_packages.PackageContentProvider recursiveInterpret func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError) moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry + packageReplaceOptions map[string]string } func (builtin *importModuleCapabilities) Interpret(locatorOfModuleInWhichThisBuiltInIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) { - moduleInPackageStarlarkStr, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, ModuleFileArgName) + moduleLocatorArgValue, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, ModuleFileArgName) if err != nil { return nil, explicitInterpretationError(err) } - moduleInPackage := moduleInPackageStarlarkStr.GoString() - moduleInPackage, relativePathParsingInterpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeModuleLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, moduleInPackage) + relativeOrAbsoluteModuleLocator := moduleLocatorArgValue.GoString() + absoluteModuleLocator, relativePathParsingInterpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, relativeOrAbsoluteModuleLocator, builtin.packageReplaceOptions) if relativePathParsingInterpretationErr != nil { return nil, relativePathParsingInterpretationErr } + logrus.Debugf("importing module from absolute locator '%s'", absoluteModuleLocator) var loadInProgress *startosis_packages.ModuleCacheEntry - cacheEntry, found := builtin.moduleGlobalCache[moduleInPackage] + cacheEntry, found := builtin.moduleGlobalCache[absoluteModuleLocator] if found && cacheEntry == loadInProgress { return nil, startosis_errors.NewInterpretationError("There's a cycle in the import_module calls") } @@ -86,34 +91,34 @@ func (builtin *importModuleCapabilities) Interpret(locatorOfModuleInWhichThisBui return cacheEntry.GetModule(), cacheEntry.GetError() } - builtin.moduleGlobalCache[moduleInPackage] = loadInProgress + builtin.moduleGlobalCache[absoluteModuleLocator] = loadInProgress shouldUnsetLoadInProgress := true defer func() { if shouldUnsetLoadInProgress { - delete(builtin.moduleGlobalCache, moduleInPackage) + delete(builtin.moduleGlobalCache, absoluteModuleLocator) } }() // Load it. - contents, interpretationError := builtin.packageContentProvider.GetModuleContents(moduleInPackage) + contents, interpretationError := builtin.packageContentProvider.GetModuleContents(absoluteModuleLocator) if interpretationError != nil { - return nil, startosis_errors.WrapWithInterpretationError(interpretationError, "An error occurred while loading the module '%v'", moduleInPackage) + return nil, startosis_errors.WrapWithInterpretationError(interpretationError, "An error occurred while loading the module '%v'", absoluteModuleLocator) } - globalVariables, interpretationErr := builtin.recursiveInterpret(moduleInPackage, contents) + globalVariables, interpretationErr := builtin.recursiveInterpret(absoluteModuleLocator, contents) // the above error goes unchecked as it needs to be persisted to the cache and then returned to the parent loader // Update the cache. if interpretationErr == nil { newModule := &starlarkstruct.Module{ - Name: moduleInPackage, + Name: absoluteModuleLocator, Members: globalVariables, } cacheEntry = startosis_packages.NewModuleCacheEntry(newModule, nil) } else { cacheEntry = startosis_packages.NewModuleCacheEntry(nil, interpretationErr) } - builtin.moduleGlobalCache[moduleInPackage] = cacheEntry + builtin.moduleGlobalCache[absoluteModuleLocator] = cacheEntry shouldUnsetLoadInProgress = false if cacheEntry.GetError() != nil { diff --git a/core/server/api_container/server/startosis_engine/builtins/read_file/read_file.go b/core/server/api_container/server/startosis_engine/builtins/read_file/read_file.go index cac685ebed..c4173a5bab 100644 --- a/core/server/api_container/server/startosis_engine/builtins/read_file/read_file.go +++ b/core/server/api_container/server/startosis_engine/builtins/read_file/read_file.go @@ -15,7 +15,11 @@ const ( SrcArgName = "src" ) -func NewReadFileHelper(packageId string, packageContentProvider startosis_packages.PackageContentProvider) *kurtosis_helper.KurtosisHelper { +func NewReadFileHelper( + packageId string, + packageContentProvider startosis_packages.PackageContentProvider, + packageReplaceOptions map[string]string, +) *kurtosis_helper.KurtosisHelper { return &kurtosis_helper.KurtosisHelper{ KurtosisBaseBuiltin: &kurtosis_starlark_framework.KurtosisBaseBuiltin{ Name: ReadFileBuiltinName, @@ -33,12 +37,14 @@ func NewReadFileHelper(packageId string, packageContentProvider startosis_packag Capabilities: &readFileCapabilities{ packageContentProvider: packageContentProvider, + packageReplaceOptions: packageReplaceOptions, }, } } type readFileCapabilities struct { packageContentProvider startosis_packages.PackageContentProvider + packageReplaceOptions map[string]string } func (builtin *readFileCapabilities) Interpret(locatorOfModuleInWhichThisBuiltInIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) { @@ -47,7 +53,7 @@ func (builtin *readFileCapabilities) Interpret(locatorOfModuleInWhichThisBuiltIn return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for arg '%s'", srcValue) } fileToReadStr := srcValue.GoString() - fileToReadStr, relativePathParsingInterpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeModuleLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, fileToReadStr) + fileToReadStr, relativePathParsingInterpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, fileToReadStr, builtin.packageReplaceOptions) if relativePathParsingInterpretationErr != nil { return nil, relativePathParsingInterpretationErr } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_builtins.go b/core/server/api_container/server/startosis_engine/kurtosis_builtins.go index 4c6ce8255f..571dbdae31 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_builtins.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_builtins.go @@ -52,7 +52,13 @@ func Predeclared() starlark.StringDict { // can have an effect at both interpretation and execution time. // // Examples: add_service, exec, wait, etc. -func KurtosisPlanInstructions(packageId string, serviceNetwork service_network.ServiceNetwork, runtimeValueStore *runtime_value_store.RuntimeValueStore, packageContentProvider startosis_packages.PackageContentProvider) []*kurtosis_plan_instruction.KurtosisPlanInstruction { +func KurtosisPlanInstructions( + packageId string, + serviceNetwork service_network.ServiceNetwork, + runtimeValueStore *runtime_value_store.RuntimeValueStore, + packageContentProvider startosis_packages.PackageContentProvider, + packageReplaceOptions map[string]string, +) []*kurtosis_plan_instruction.KurtosisPlanInstruction { return []*kurtosis_plan_instruction.KurtosisPlanInstruction{ add_service.NewAddService(serviceNetwork, runtimeValueStore), add_service.NewAddServices(serviceNetwork, runtimeValueStore), @@ -67,7 +73,7 @@ func KurtosisPlanInstructions(packageId string, serviceNetwork service_network.S tasks.NewRunShService(serviceNetwork, runtimeValueStore), stop_service.NewStopService(serviceNetwork), store_service_files.NewStoreServiceFiles(serviceNetwork), - upload_files.NewUploadFiles(packageId, serviceNetwork, packageContentProvider), + upload_files.NewUploadFiles(packageId, serviceNetwork, packageContentProvider, packageReplaceOptions), wait.NewWait(serviceNetwork, runtimeValueStore), } } @@ -79,11 +85,11 @@ func KurtosisPlanInstructions(packageId string, serviceNetwork service_network.S // Kurtosis enclave. // // Example: read_file, import_package, etc. -func KurtosisHelpers(packageId string, recursiveInterpret func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError), packageContentProvider startosis_packages.PackageContentProvider, packageGlobalCache map[string]*startosis_packages.ModuleCacheEntry) []*starlark.Builtin { +func KurtosisHelpers(packageId string, recursiveInterpret func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError), packageContentProvider startosis_packages.PackageContentProvider, packageGlobalCache map[string]*startosis_packages.ModuleCacheEntry, packageReplaceOptions map[string]string) []*starlark.Builtin { return []*starlark.Builtin{ - starlark.NewBuiltin(import_module.ImportModuleBuiltinName, import_module.NewImportModule(packageId, recursiveInterpret, packageContentProvider, packageGlobalCache).CreateBuiltin()), + starlark.NewBuiltin(import_module.ImportModuleBuiltinName, import_module.NewImportModule(packageId, recursiveInterpret, packageContentProvider, packageGlobalCache, packageReplaceOptions).CreateBuiltin()), starlark.NewBuiltin(print_builtin.PrintBuiltinName, print_builtin.GeneratePrintBuiltin()), - starlark.NewBuiltin(read_file.ReadFileBuiltinName, read_file.NewReadFileHelper(packageId, packageContentProvider).CreateBuiltin()), + starlark.NewBuiltin(read_file.ReadFileBuiltinName, read_file.NewReadFileHelper(packageId, packageContentProvider, packageReplaceOptions).CreateBuiltin()), } } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files/upload_files.go b/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files/upload_files.go index 160bb1e5dd..eed4e32cae 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files/upload_files.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_instruction/upload_files/upload_files.go @@ -30,7 +30,12 @@ const ( readOnlyFilePerm = 0400 ) -func NewUploadFiles(packageId string, serviceNetwork service_network.ServiceNetwork, packageContentProvider startosis_packages.PackageContentProvider) *kurtosis_plan_instruction.KurtosisPlanInstruction { +func NewUploadFiles( + packageId string, + serviceNetwork service_network.ServiceNetwork, + packageContentProvider startosis_packages.PackageContentProvider, + packageReplaceOptions map[string]string, +) *kurtosis_plan_instruction.KurtosisPlanInstruction { return &kurtosis_plan_instruction.KurtosisPlanInstruction{ KurtosisBaseBuiltin: &kurtosis_starlark_framework.KurtosisBaseBuiltin{ Name: UploadFilesBuiltinName, @@ -58,10 +63,11 @@ func NewUploadFiles(packageId string, serviceNetwork service_network.ServiceNetw serviceNetwork: serviceNetwork, packageContentProvider: packageContentProvider, - src: "", // populated at interpretation time - artifactName: "", // populated at interpretation time - archivePathOnDisk: "", // populated at interpretation time - filesArtifactMd5: nil, // populated at interpretation time + src: "", // populated at interpretation time + artifactName: "", // populated at interpretation time + archivePathOnDisk: "", // populated at interpretation time + filesArtifactMd5: nil, // populated at interpretation time + packageReplaceOptions: packageReplaceOptions, } }, @@ -76,10 +82,11 @@ type UploadFilesCapabilities struct { serviceNetwork service_network.ServiceNetwork packageContentProvider startosis_packages.PackageContentProvider - src string - artifactName string - archivePathOnDisk string - filesArtifactMd5 []byte + src string + artifactName string + archivePathOnDisk string + filesArtifactMd5 []byte + packageReplaceOptions map[string]string } func (builtin *UploadFilesCapabilities) Interpret(locatorOfModuleInWhichThisBuiltInIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) { @@ -102,7 +109,7 @@ func (builtin *UploadFilesCapabilities) Interpret(locatorOfModuleInWhichThisBuil return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", SrcArgName) } - absoluteLocator, interpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeModuleLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, src.GoString()) + absoluteLocator, interpretationErr := builtin.packageContentProvider.GetAbsoluteLocatorForRelativeLocator(locatorOfModuleInWhichThisBuiltInIsBeingCalled, src.GoString(), builtin.packageReplaceOptions) if interpretationErr != nil { return nil, startosis_errors.WrapWithInterpretationError(interpretationErr, "Tried to convert locator '%v' into absolute locator but failed", src.GoString()) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go index 0a5805f3a7..aa5589091b 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_service_framework_test.go @@ -25,13 +25,13 @@ type addServiceTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestAddService() { - suite.serviceNetwork.EXPECT().ExistServiceRegistration(TestServiceName).Times(1).Return(false, nil) + suite.serviceNetwork.EXPECT().ExistServiceRegistration(testServiceName).Times(1).Return(false, nil) suite.serviceNetwork.EXPECT().AddService( mock.Anything, - TestServiceName, + testServiceName, mock.MatchedBy(func(serviceConfig *service.ServiceConfig) bool { expectedServiceConfig := service.NewServiceConfig( - TestContainerImageName, + testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, nil, @@ -51,7 +51,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddService() { return true }), ).Times(1).Return( - service.NewService(service.NewServiceRegistration(TestServiceName, TestServiceUuid, TestEnclaveUuid, nil, string(TestServiceName)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, "", nil, nil, nil)), + service.NewService(service.NewServiceRegistration(testServiceName, testServiceUuid, testEnclaveUuid, nil, string(testServiceName)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, "", nil, nil, nil)), nil, ) @@ -67,8 +67,8 @@ func (t *addServiceTestCase) GetInstruction() *kurtosis_plan_instruction.Kurtosi } func (t *addServiceTestCase) GetStarlarkCode() string { - serviceConfig := fmt.Sprintf("ServiceConfig(image=%q)", TestContainerImageName) - return fmt.Sprintf(`%s(%s=%q, %s=%s)`, add_service.AddServiceBuiltinName, add_service.ServiceNameArgName, TestServiceName, add_service.ServiceConfigArgName, serviceConfig) + serviceConfig := fmt.Sprintf("ServiceConfig(image=%q)", testContainerImageName) + return fmt.Sprintf(`%s(%s=%q, %s=%s)`, add_service.AddServiceBuiltinName, add_service.ServiceNameArgName, testServiceName, add_service.ServiceConfigArgName, serviceConfig) } func (t *addServiceTestCase) GetStarlarkCodeForAssertion() string { @@ -79,9 +79,9 @@ func (t *addServiceTestCase) Assert(interpretationResult starlark.Value, executi serviceObj, ok := interpretationResult.(*kurtosis_types.Service) require.True(t, ok, "interpretation result should be a dictionary") require.NotNil(t, serviceObj) - expectedServiceObj := fmt.Sprintf(`Service\(name="%v", hostname="{{kurtosis:[0-9a-f]{32}:hostname.runtime_value}}", ip_address="{{kurtosis:[0-9a-f]{32}:ip_address.runtime_value}}", ports={}\)`, TestServiceName) + expectedServiceObj := fmt.Sprintf(`Service\(name="%v", hostname="{{kurtosis:[0-9a-f]{32}:hostname.runtime_value}}", ip_address="{{kurtosis:[0-9a-f]{32}:ip_address.runtime_value}}", ports={}\)`, testServiceName) require.Regexp(t, expectedServiceObj, serviceObj.String()) - expectedExecutionResult := fmt.Sprintf("Service '%s' added with service UUID '%s'", TestServiceName, TestServiceUuid) + expectedExecutionResult := fmt.Sprintf("Service '%s' added with service UUID '%s'", testServiceName, testServiceUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go index a398633c3c..58fa695f1e 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/add_services_framework_test.go @@ -28,8 +28,8 @@ type addServicesTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { - suite.serviceNetwork.EXPECT().ExistServiceRegistration(TestServiceName).Times(1).Return(false, nil) - suite.serviceNetwork.EXPECT().ExistServiceRegistration(TestServiceName2).Times(1).Return(false, nil) + suite.serviceNetwork.EXPECT().ExistServiceRegistration(testServiceName).Times(1).Return(false, nil) + suite.serviceNetwork.EXPECT().ExistServiceRegistration(testServiceName2).Times(1).Return(false, nil) suite.serviceNetwork.EXPECT().UpdateServices( mock.Anything, map[service.ServiceName]*service.ServiceConfig{}, @@ -43,11 +43,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { mock.Anything, mock.MatchedBy(func(configs map[service.ServiceName]*service.ServiceConfig) bool { suite.Require().Len(configs, 2) - suite.Require().Contains(configs, TestServiceName) - suite.Require().Contains(configs, TestServiceName2) + suite.Require().Contains(configs, testServiceName) + suite.Require().Contains(configs, testServiceName2) expectedServiceConfig1 := service.NewServiceConfig( - TestContainerImageName, + testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, nil, @@ -61,11 +61,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { 0, 0, ) - actualServiceConfig1 := configs[TestServiceName] + actualServiceConfig1 := configs[testServiceName] suite.Assert().Equal(expectedServiceConfig1, actualServiceConfig1) expectedServiceConfig2 := service.NewServiceConfig( - TestContainerImageName, + testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, nil, @@ -73,21 +73,21 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { map[string]string{}, nil, nil, - TestCpuAllocation, - TestMemoryAllocation, + testCpuAllocation, + testMemoryAllocation, service_config.DefaultPrivateIPAddrPlaceholder, 0, 0, ) - actualServiceConfig2 := configs[TestServiceName2] + actualServiceConfig2 := configs[testServiceName2] suite.Assert().Equal(expectedServiceConfig2, actualServiceConfig2) return true }), mock.Anything, ).Times(1).Return( map[service.ServiceName]*service.Service{ - TestServiceName: service.NewService(service.NewServiceRegistration(TestServiceName, TestServiceUuid, TestEnclaveUuid, nil, string(TestServiceName)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, TestContainerImageName, nil, nil, nil)), - TestServiceName2: service.NewService(service.NewServiceRegistration(TestServiceName2, TestServiceUuid2, TestEnclaveUuid, nil, string(TestServiceName2)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, TestContainerImageName, nil, nil, nil)), + testServiceName: service.NewService(service.NewServiceRegistration(testServiceName, testServiceUuid, testEnclaveUuid, nil, string(testServiceName)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)), + testServiceName2: service.NewService(service.NewServiceRegistration(testServiceName2, testServiceUuid2, testEnclaveUuid, nil, string(testServiceName2)), nil, nil, nil, container.NewContainer(container.ContainerStatus_Running, testContainerImageName, nil, nil, nil)), }, map[service.ServiceName]error{}, nil, @@ -95,11 +95,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName), - TestReadyConditionsRecipePortId, - TestGetRequestMethod, + string(testServiceName), + testReadyConditionsRecipePortId, + testGetRequestMethod, "", - TestReadyConditionsRecipeEndpoint, + testReadyConditionsRecipeEndpoint, "", ).Times(1).Return(&http.Response{ Status: "200 OK", @@ -109,7 +109,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { ProtoMinor: 1, Header: http.Header{}, Request: &http.Request{ //nolint:exhaustruct - Method: TestGetRequestMethod, + Method: testGetRequestMethod, URL: &url.URL{}, //nolint:exhaustruct }, Close: true, @@ -123,11 +123,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName2), - TestReadyConditions2RecipePortId, - TestGetRequestMethod, + string(testServiceName2), + testReadyConditions2RecipePortId, + testGetRequestMethod, "", - TestReadyConditions2RecipeEndpoint, + testReadyConditions2RecipeEndpoint, "", ).Times(1).Return(&http.Response{ Status: "201 OK", @@ -137,7 +137,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestAddServices() { ProtoMinor: 1, Header: http.Header{}, Request: &http.Request{ - Method: TestGetRequestMethod, + Method: testGetRequestMethod, URL: &url.URL{ //nolint:exhaustruct Path: "", Scheme: "", @@ -193,18 +193,18 @@ func (t *addServicesTestCase) GetInstruction() *kurtosis_plan_instruction.Kurtos func (t *addServicesTestCase) GetStarlarkCode() string { service1ReadyConditionsScriptPart := getDefaultReadyConditionsScriptPart() service2ReadyConditionsScriptPart := getCustomReadyConditionsScripPart( - TestReadyConditions2RecipePortId, - TestReadyConditions2RecipeEndpoint, - TestReadyConditions2RecipeExtract, - TestReadyConditions2Field, - TestReadyConditions2Assertion, - TestReadyConditions2Target, - TestReadyConditions2Interval, - TestReadyConditions2Timeout, + testReadyConditions2RecipePortId, + testReadyConditions2RecipeEndpoint, + testReadyConditions2RecipeExtract, + testReadyConditions2Field, + testReadyConditions2Assertion, + testReadyConditions2Target, + testReadyConditions2Interval, + testReadyConditions2Timeout, ) - serviceConfig1 := fmt.Sprintf("ServiceConfig(image=%q, ready_conditions=%s)", TestContainerImageName, service1ReadyConditionsScriptPart) - serviceConfig2 := fmt.Sprintf("ServiceConfig(image=%q, cpu_allocation=%d, memory_allocation=%d, ready_conditions=%s)", TestContainerImageName, TestCpuAllocation, TestMemoryAllocation, service2ReadyConditionsScriptPart) - return fmt.Sprintf(`%s(%s={%q: %s, %q: %s})`, add_service.AddServicesBuiltinName, add_service.ConfigsArgName, TestServiceName, serviceConfig1, TestServiceName2, serviceConfig2) + serviceConfig1 := fmt.Sprintf("ServiceConfig(image=%q, ready_conditions=%s)", testContainerImageName, service1ReadyConditionsScriptPart) + serviceConfig2 := fmt.Sprintf("ServiceConfig(image=%q, cpu_allocation=%d, memory_allocation=%d, ready_conditions=%s)", testContainerImageName, testCpuAllocation, testMemoryAllocation, service2ReadyConditionsScriptPart) + return fmt.Sprintf(`%s(%s={%q: %s, %q: %s})`, add_service.AddServicesBuiltinName, add_service.ConfigsArgName, testServiceName, serviceConfig1, testServiceName2, serviceConfig2) } func (t *addServicesTestCase) GetStarlarkCodeForAssertion() string { @@ -215,10 +215,10 @@ func (t *addServicesTestCase) Assert(interpretationResult starlark.Value, execut resultDict, ok := interpretationResult.(*starlark.Dict) require.True(t, ok, "interpretation result should be a dictionary") require.Equal(t, resultDict.Len(), 2) - require.Contains(t, resultDict.Keys(), starlark.String(TestServiceName)) - require.Contains(t, resultDict.Keys(), starlark.String(TestServiceName2)) + require.Contains(t, resultDict.Keys(), starlark.String(testServiceName)) + require.Contains(t, resultDict.Keys(), starlark.String(testServiceName2)) require.Contains(t, *executionResult, "Successfully added the following '2' services:") - require.Contains(t, *executionResult, fmt.Sprintf("Service '%s' added with UUID '%s'", TestServiceName, TestServiceUuid)) - require.Contains(t, *executionResult, fmt.Sprintf("Service '%s' added with UUID '%s'", TestServiceName2, TestServiceUuid2)) + require.Contains(t, *executionResult, fmt.Sprintf("Service '%s' added with UUID '%s'", testServiceName, testServiceUuid)) + require.Contains(t, *executionResult, fmt.Sprintf("Service '%s' added with UUID '%s'", testServiceName2, testServiceUuid2)) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_file_artifact_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_file_artifact_framework_test.go index 83cb899211..2b54e31fe8 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_file_artifact_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_file_artifact_framework_test.go @@ -19,7 +19,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestDirectoryFileArtifact() { } func (t *directoryFileArtifactTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, TestFilesArtifactName1) + return fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, testFilesArtifactName1) } func (t *directoryFileArtifactTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { @@ -29,7 +29,7 @@ func (t *directoryFileArtifactTestCase) Assert(typeValue builtin_argument.Kurtos artifactName, found, err := directoryStarlark.GetArtifactNameIfSet() require.Nil(t, err) require.True(t, found) - require.Equal(t, TestFilesArtifactName1, artifactName) + require.Equal(t, testFilesArtifactName1, artifactName) persistentKey, found, err := directoryStarlark.GetPersistentKeyIfSet() require.Nil(t, err) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_persistent_directory_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_persistent_directory_framework_test.go index a569a80ede..d6ac99ee88 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_persistent_directory_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/directory_persistent_directory_framework_test.go @@ -19,7 +19,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestDirectoryPersistentDirectory( } func (t *directoryPersistentDirectoryTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, TestPersistentDirectoryKey) + return fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, testPersistentDirectoryKey) } func (t *directoryPersistentDirectoryTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { @@ -34,5 +34,5 @@ func (t *directoryPersistentDirectoryTestCase) Assert(typeValue builtin_argument persistentKey, found, err := directoryStarlark.GetPersistentKeyIfSet() require.Nil(t, err) require.True(t, found) - require.Equal(t, TestPersistentDirectoryKey, persistentKey) + require.Equal(t, testPersistentDirectoryKey, persistentKey) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go index 39fd52ef42..93af3c7b67 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/exec_recipe_framework_test.go @@ -23,7 +23,7 @@ type execRecipeTestCase struct { func (suite *KurtosisTypeConstructorTestSuite) TestExecRecipe() { suite.serviceNetwork.EXPECT().RunExec( mock.Anything, - string(TestServiceName), + string(testServiceName), []string{"echo", "run"}, ).Times(1).Return( exec_result.NewExecResult(0, "run"), @@ -50,7 +50,7 @@ func (t *execRecipeTestCase) Assert(typeValue builtin_argument.KurtosisValueType execRecipe, ok := typeValue.(*recipe.ExecRecipe) require.True(t, ok) - _, err := execRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, TestServiceName) + _, err := execRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, testServiceName) require.NoError(t, err) returnValue, err := execRecipe.CreateStarlarkReturnValue("result-fake-uuid") diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go index f62fa146d5..72dc5d5e49 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_no_extractor_test.go @@ -24,8 +24,8 @@ type getHttpRequestRecipeNoExtractorTestCase struct { func (suite *KurtosisTypeConstructorTestSuite) TestGetHttpRequestRecipeNoExtractor() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName), - TestPrivatePortId, + string(testServiceName), + testPrivatePortId, "GET", "", "/test", @@ -58,14 +58,14 @@ func (suite *KurtosisTypeConstructorTestSuite) TestGetHttpRequestRecipeNoExtract } func (t *getHttpRequestRecipeNoExtractorTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", recipe.GetHttpRecipeTypeName, recipe.PortIdAttr, TestPrivatePortId, recipe.EndpointAttr, "/test") + return fmt.Sprintf("%s(%s=%q, %s=%q)", recipe.GetHttpRecipeTypeName, recipe.PortIdAttr, testPrivatePortId, recipe.EndpointAttr, "/test") } func (t *getHttpRequestRecipeNoExtractorTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { getHttpRequestRecipe, ok := typeValue.(*recipe.GetHttpRequestRecipe) require.True(t, ok) - _, err := getHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, TestServiceName) + _, err := getHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, testServiceName) require.NoError(t, err) returnValue, interpretationErr := getHttpRequestRecipe.CreateStarlarkReturnValue("result-fake-uuid") diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go index 9aac54f733..0fcd60750a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/get_http_request_recipe_test.go @@ -28,8 +28,8 @@ type getHttpRequestRecipeTestCase struct { func (suite *KurtosisTypeConstructorTestSuite) TestGetHttpRequestRecipe() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName), - TestPrivatePortId, + string(testServiceName), + testPrivatePortId, "GET", "", "/test", @@ -63,14 +63,14 @@ func (suite *KurtosisTypeConstructorTestSuite) TestGetHttpRequestRecipe() { func (t *getHttpRequestRecipeTestCase) GetStarlarkCode() string { extractors := `{"result": ".value"}` - return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%s)", recipe.GetHttpRecipeTypeName, recipe.PortIdAttr, TestPrivatePortId, recipe.EndpointAttr, "/test", recipe.ExtractAttr, extractors) + return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%s)", recipe.GetHttpRecipeTypeName, recipe.PortIdAttr, testPrivatePortId, recipe.EndpointAttr, "/test", recipe.ExtractAttr, extractors) } func (t *getHttpRequestRecipeTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { getHttpRequestRecipe, ok := typeValue.(*recipe.GetHttpRequestRecipe) require.True(t, ok) - _, err := getHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, TestServiceName) + _, err := getHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, testServiceName) require.NoError(t, err) returnValue, interpretationErr := getHttpRequestRecipe.CreateStarlarkReturnValue("result-fake-uuid") diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_framework_test.go index 947b45b4b4..337c853456 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_framework_test.go @@ -19,7 +19,7 @@ const ( var ( importModule_mockStarlarkModule = &starlarkstruct.Module{ - Name: TestModuleFileName, + Name: testModuleFileName, Members: starlark.StringDict{ importModule_moduleConstKey: starlark.String("Hello World!"), }, @@ -38,8 +38,8 @@ func (suite *KurtosisHelperTestSuite) TestImportFile() { // start with an empty cache to validate it gets populated moduleGlobalCache := map[string]*startosis_packages.ModuleCacheEntry{} - suite.packageContentProvider.EXPECT().GetModuleContents(TestModuleFileName).Return("Hello World!", nil) - suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeModuleLocator(startosis_constants.PackageIdPlaceholderForStandaloneScript, TestModuleRelativeLocator).Return(TestModuleFileName, nil) + suite.packageContentProvider.EXPECT().GetModuleContents(testModuleFileName).Return("Hello World!", nil) + suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil) suite.run(&importModuleTestCase{ T: suite.T(), @@ -52,11 +52,11 @@ func (t *importModuleTestCase) GetHelper() *kurtosis_helper.KurtosisHelper { recursiveInterpret := func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError) { return importModule_mockStarlarkModule.Members, nil } - return import_module.NewImportModule(TestModulePackageId, recursiveInterpret, t.packageContentProvider, t.moduleGlobalCache) + return import_module.NewImportModule(testModulePackageId, recursiveInterpret, t.packageContentProvider, t.moduleGlobalCache, testNoPackageReplaceOptions) } func (t *importModuleTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", import_module.ImportModuleBuiltinName, import_module.ModuleFileArgName, TestModuleRelativeLocator) + return fmt.Sprintf("%s(%s=%q)", import_module.ImportModuleBuiltinName, import_module.ModuleFileArgName, testModuleRelativeLocator) } func (t *importModuleTestCase) GetStarlarkCodeForAssertion() string { @@ -66,7 +66,7 @@ func (t *importModuleTestCase) GetStarlarkCodeForAssertion() string { func (t *importModuleTestCase) Assert(result starlark.Value) { loadedModule, ok := result.(*starlarkstruct.Module) require.True(t, ok, "object returned was not a starlark module") - require.Equal(t, loadedModule.Name, TestModuleFileName) + require.Equal(t, loadedModule.Name, testModuleFileName) require.Len(t, loadedModule.Members, 1) require.Contains(t, loadedModule.Members, importModule_moduleConstKey) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_with_local_absolute_locator_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_with_local_absolute_locator_framework_test.go index 02b24761cc..67f9404ca2 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_with_local_absolute_locator_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/import_module_with_local_absolute_locator_framework_test.go @@ -17,7 +17,7 @@ const ( var ( importModuleWithLocalAbsoluteLocator_mockStarlarkModule = &starlarkstruct.Module{ - Name: TestModuleFileName, + Name: testModuleFileName, Members: starlark.StringDict{ importModule_moduleConstKey: starlark.String("Hello World!"), }, @@ -50,11 +50,11 @@ func (t *importModuleWithLocalAbsoluteLocatorTestCase) GetHelper() *kurtosis_hel recursiveInterpret := func(moduleId string, scriptContent string) (starlark.StringDict, *startosis_errors.InterpretationError) { return importModuleWithLocalAbsoluteLocator_mockStarlarkModule.Members, nil } - return import_module.NewImportModule(TestModulePackageId, recursiveInterpret, t.packageContentProvider, t.moduleGlobalCache) + return import_module.NewImportModule(testModulePackageId, recursiveInterpret, t.packageContentProvider, t.moduleGlobalCache, testNoPackageReplaceOptions) } func (t *importModuleWithLocalAbsoluteLocatorTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", import_module.ImportModuleBuiltinName, import_module.ModuleFileArgName, TestModuleFileName) + return fmt.Sprintf("%s(%s=%q)", import_module.ImportModuleBuiltinName, import_module.ModuleFileArgName, testModuleFileName) } func (t *importModuleWithLocalAbsoluteLocatorTestCase) GetStarlarkCodeForAssertion() string { diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_full_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_full_framework_test.go index 69d9418e70..5806853e4a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_full_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_full_framework_test.go @@ -24,13 +24,13 @@ func (t *portSpecFullTestCase) GetStarlarkCode() string { return fmt.Sprintf("%s(%s=%d, %s=%q, %s=%q, %s=%q)", port_spec.PortSpecTypeName, port_spec.PortNumberAttr, - TestPrivatePortNumber, + testPrivatePortNumber, port_spec.TransportProtocolAttr, - TestPrivatePortProtocolStr, + testPrivatePortProtocolStr, port_spec.PortApplicationProtocolAttr, - TestPrivateApplicationProtocol, + testPrivateApplicationProtocol, port_spec.WaitAttr, - TestWaitConfiguration, + testWaitConfiguration, ) } @@ -40,9 +40,9 @@ func (t *portSpecFullTestCase) Assert(typeValue builtin_argument.KurtosisValueTy portSpec, err := portSpecStarlark.ToKurtosisType() require.Nil(t, err) - waitDuration, errParsingDuration := time.ParseDuration(TestWaitConfiguration) + waitDuration, errParsingDuration := time.ParseDuration(testWaitConfiguration) require.NoError(t, errParsingDuration) - expectedPortSpec, errPortCreation := port_spec2.NewPortSpec(TestPrivatePortNumber, TestPrivatePortProtocol, TestPrivateApplicationProtocol, port_spec2.NewWait(waitDuration)) + expectedPortSpec, errPortCreation := port_spec2.NewPortSpec(testPrivatePortNumber, testPrivatePortProtocol, testPrivateApplicationProtocol, port_spec2.NewWait(waitDuration)) require.NoError(t, errPortCreation) require.Equal(t, expectedPortSpec, portSpec) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_minimal_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_minimal_framework_test.go index 2cdfffa751..cd1fbdd072 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_minimal_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/port_spec_minimal_framework_test.go @@ -21,7 +21,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestPortSpecMinimal() { } func (t *portSpecMinimalTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%d)", port_spec_starlark.PortSpecTypeName, port_spec_starlark.PortNumberAttr, TestPrivatePortNumber) + return fmt.Sprintf("%s(%s=%d)", port_spec_starlark.PortSpecTypeName, port_spec_starlark.PortNumberAttr, testPrivatePortNumber) } func (t *portSpecMinimalTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { @@ -30,9 +30,9 @@ func (t *portSpecMinimalTestCase) Assert(typeValue builtin_argument.KurtosisValu portSpec, err := portSpecStarlark.ToKurtosisType() require.Nil(t, err) - waitDuration, errParsingDuration := time.ParseDuration(TestWaitDefaultValue) + waitDuration, errParsingDuration := time.ParseDuration(testWaitDefaultValue) require.NoError(t, errParsingDuration) - expectedPortSpec, errPortCreation := port_spec.NewPortSpec(TestPrivatePortNumber, port_spec.TransportProtocol_TCP, "", port_spec.NewWait(waitDuration)) + expectedPortSpec, errPortCreation := port_spec.NewPortSpec(testPrivatePortNumber, port_spec.TransportProtocol_TCP, "", port_spec.NewWait(waitDuration)) require.NoError(t, errPortCreation) require.Equal(t, expectedPortSpec, portSpec) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go index a9eced7464..004b6ca891 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_minimal_test.go @@ -24,8 +24,8 @@ type postHttpRequestRecipeMinimalTestCase struct { func (suite *KurtosisTypeConstructorTestSuite) TestPostHttpRequestRecipeMinimal() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName), - TestPrivatePortId, + string(testServiceName), + testPrivatePortId, "POST", "application/json", "/test", @@ -58,14 +58,14 @@ func (suite *KurtosisTypeConstructorTestSuite) TestPostHttpRequestRecipeMinimal( } func (t *postHttpRequestRecipeMinimalTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", recipe.PostHttpRecipeTypeName, recipe.PortIdAttr, TestPrivatePortId, recipe.EndpointAttr, "/test") + return fmt.Sprintf("%s(%s=%q, %s=%q)", recipe.PostHttpRecipeTypeName, recipe.PortIdAttr, testPrivatePortId, recipe.EndpointAttr, "/test") } func (t *postHttpRequestRecipeMinimalTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { postHttpRequestRecipe, ok := typeValue.(*recipe.PostHttpRequestRecipe) require.True(t, ok) - _, err := postHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, TestServiceName) + _, err := postHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, testServiceName) require.NoError(t, err) returnValue, interpretationErr := postHttpRequestRecipe.CreateStarlarkReturnValue("result-fake-uuid") diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go index 4fc48ac033..e73f8c7622 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/post_http_request_recipe_test.go @@ -28,8 +28,8 @@ type postHttpRequestRecipeTestCase struct { func (suite *KurtosisTypeConstructorTestSuite) TestPostHttpRequestRecipe() { suite.serviceNetwork.EXPECT().HttpRequestService( mock.Anything, - string(TestServiceName), - TestPrivatePortId, + string(testServiceName), + testPrivatePortId, "POST", "application/json", "/test", @@ -63,14 +63,14 @@ func (suite *KurtosisTypeConstructorTestSuite) TestPostHttpRequestRecipe() { func (t *postHttpRequestRecipeTestCase) GetStarlarkCode() string { extractors := `{"result": ".value"}` - return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%q, %s=%s)", recipe.PostHttpRecipeTypeName, recipe.PortIdAttr, TestPrivatePortId, recipe.EndpointAttr, "/test", recipe.RequestBodyAttr, "{}", recipe.ContentTypeAttr, "application/json", recipe.ExtractAttr, extractors) + return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%q, %s=%s)", recipe.PostHttpRecipeTypeName, recipe.PortIdAttr, testPrivatePortId, recipe.EndpointAttr, "/test", recipe.RequestBodyAttr, "{}", recipe.ContentTypeAttr, "application/json", recipe.ExtractAttr, extractors) } func (t *postHttpRequestRecipeTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { postHttpRequestRecipe, ok := typeValue.(*recipe.PostHttpRequestRecipe) require.True(t, ok) - _, err := postHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, TestServiceName) + _, err := postHttpRequestRecipe.Execute(context.Background(), t.serviceNetwork, t.runtimeValueStore, testServiceName) require.NoError(t, err) returnValue, interpretationErr := postHttpRequestRecipe.CreateStarlarkReturnValue("result-fake-uuid") diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_framework_test.go index 4c060ab8ee..27fd68c5f9 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_framework_test.go @@ -18,8 +18,8 @@ type readFileTestCase struct { } func (suite *KurtosisHelperTestSuite) TestReadFile() { - suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeModuleLocator(startosis_constants.PackageIdPlaceholderForStandaloneScript, TestModuleRelativeLocator).Return(TestModuleFileName, nil) - suite.packageContentProvider.EXPECT().GetModuleContents(TestModuleFileName).Return("Hello World!", nil) + suite.packageContentProvider.EXPECT().GetAbsoluteLocatorForRelativeLocator(startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions).Return(testModuleFileName, nil) + suite.packageContentProvider.EXPECT().GetModuleContents(testModuleFileName).Return("Hello World!", nil) suite.run(&readFileTestCase{ T: suite.T(), @@ -28,11 +28,11 @@ func (suite *KurtosisHelperTestSuite) TestReadFile() { } func (t *readFileTestCase) GetHelper() *kurtosis_helper.KurtosisHelper { - return read_file.NewReadFileHelper(TestModulePackageId, t.packageContentProvider) + return read_file.NewReadFileHelper(testModulePackageId, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *readFileTestCase) GetStarlarkCode() string { - return fmt.Sprintf(`%s(%s=%q)`, read_file.ReadFileBuiltinName, read_file.SrcArgName, TestModuleRelativeLocator) + return fmt.Sprintf(`%s(%s=%q)`, read_file.ReadFileBuiltinName, read_file.SrcArgName, testModuleRelativeLocator) } func (t *readFileTestCase) GetStarlarkCodeForAssertion() string { @@ -40,7 +40,7 @@ func (t *readFileTestCase) GetStarlarkCodeForAssertion() string { } func (t *readFileTestCase) Assert(result starlark.Value) { - t.packageContentProvider.AssertCalled(t, "GetAbsoluteLocatorForRelativeModuleLocator", startosis_constants.PackageIdPlaceholderForStandaloneScript, TestModuleRelativeLocator) - t.packageContentProvider.AssertCalled(t, "GetModuleContents", TestModuleFileName) + t.packageContentProvider.AssertCalled(t, "GetAbsoluteLocatorForRelativeLocator", startosis_constants.PackageIdPlaceholderForStandaloneScript, testModuleRelativeLocator, testNoPackageReplaceOptions) + t.packageContentProvider.AssertCalled(t, "GetModuleContents", testModuleFileName) require.Equal(t, result, starlark.String("Hello World!")) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_with_local_absolute_locator_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_with_local_absolute_locator_framework_test.go index ed5a332627..20babbbe75 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_with_local_absolute_locator_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/read_file_with_local_absolute_locator_framework_test.go @@ -31,11 +31,11 @@ func (suite *KurtosisHelperTestSuite) TestReadFileWithLocalAbsoluteLocatorShould } func (t *readFileWithLocalAbsoluteLocatorTestCase) GetHelper() *kurtosis_helper.KurtosisHelper { - return read_file.NewReadFileHelper(TestModulePackageId, t.packageContentProvider) + return read_file.NewReadFileHelper(testModulePackageId, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *readFileWithLocalAbsoluteLocatorTestCase) GetStarlarkCode() string { - return fmt.Sprintf(`%s(%s=%q)`, read_file.ReadFileBuiltinName, read_file.SrcArgName, TestModuleFileName) + return fmt.Sprintf(`%s(%s=%q)`, read_file.ReadFileBuiltinName, read_file.SrcArgName, testModuleFileName) } func (t *readFileWithLocalAbsoluteLocatorTestCase) GetStarlarkCodeForAssertion() string { diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_exec_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_exec_recipe_test.go index 69f8a135d0..00a97cf8ca 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_exec_recipe_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_exec_recipe_test.go @@ -28,17 +28,17 @@ func (t *readyConditionsExecRecipeTestCase) GetStarlarkCode() string { service_config.RecipeAttr, recipe.ExecRecipeTypeName, recipe.CommandAttr, - fmt.Sprintf("[%q, %q]", TestReadyConditionsRecipeCommand[0], TestReadyConditionsRecipeCommand[1]), + fmt.Sprintf("[%q, %q]", testReadyConditionsRecipeCommand[0], testReadyConditionsRecipeCommand[1]), service_config.FieldAttr, - TestReadyConditionsField, + testReadyConditionsField, service_config.AssertionAttr, - TestReadyConditionsAssertion, + testReadyConditionsAssertion, service_config.TargetAttr, - TestReadyConditionsTarget, + testReadyConditionsTarget, service_config.IntervalAttr, - TestReadyConditionsInterval, + testReadyConditionsInterval, service_config.TimeoutAttr, - TestReadyConditionsTimeout, + testReadyConditionsTimeout, ) } @@ -55,33 +55,33 @@ func (t *readyConditionsExecRecipeTestCase) Assert(typeValue builtin_argument.Ku if assert.Nil(t, err) { command, ok := commandAttrValue.(*starlark.List) require.True(t, ok) - require.Equal(t, command.Len(), len(TestReadyConditionsRecipeCommand)) + require.Equal(t, command.Len(), len(testReadyConditionsRecipeCommand)) for i := 0; i < command.Len(); i++ { commandPart, ok := command.Index(i).(starlark.String) require.True(t, ok) - require.Equal(t, TestReadyConditionsRecipeCommand[i], commandPart.GoString()) + require.Equal(t, testReadyConditionsRecipeCommand[i], commandPart.GoString()) } } } field, err := receivedReadyConditions.GetField() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsField, field) + require.Equal(t, testReadyConditionsField, field) } assertion, err := receivedReadyConditions.GetAssertion() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsAssertion, assertion) + require.Equal(t, testReadyConditionsAssertion, assertion) } target, err := receivedReadyConditions.GetTarget() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsTarget, target.String()) + require.Equal(t, testReadyConditionsTarget, target.String()) } interval, err := receivedReadyConditions.GetInterval() if assert.Nil(t, err) { - expectedInterval, err := time.ParseDuration(TestReadyConditionsInterval) + expectedInterval, err := time.ParseDuration(testReadyConditionsInterval) if assert.Nil(t, err) { require.Equal(t, expectedInterval, interval) } @@ -89,7 +89,7 @@ func (t *readyConditionsExecRecipeTestCase) Assert(typeValue builtin_argument.Ku timeout, err := receivedReadyConditions.GetTimeout() if assert.Nil(t, err) { - expectedTimeout, err := time.ParseDuration(TestReadyConditionsTimeout) + expectedTimeout, err := time.ParseDuration(testReadyConditionsTimeout) if assert.Nil(t, err) { require.Equal(t, expectedTimeout, timeout) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_http_request_recipe_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_http_request_recipe_test.go index d6da5f6504..e6912afc27 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_http_request_recipe_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/ready_conditions_framework_http_request_recipe_test.go @@ -28,21 +28,21 @@ func (t *readyConditionsHttpRecipeTestCase) GetStarlarkCode() string { service_config.RecipeAttr, recipe.GetHttpRecipeTypeName, recipe.PortIdAttr, - TestReadyConditionsRecipePortId, + testReadyConditionsRecipePortId, recipe.EndpointAttr, - TestReadyConditionsRecipeEndpoint, + testReadyConditionsRecipeEndpoint, recipe.ExtractAttr, - TestReadyConditionsRecipeExtract, + testReadyConditionsRecipeExtract, service_config.FieldAttr, - TestReadyConditionsField, + testReadyConditionsField, service_config.AssertionAttr, - TestReadyConditionsAssertion, + testReadyConditionsAssertion, service_config.TargetAttr, - TestReadyConditionsTarget, + testReadyConditionsTarget, service_config.IntervalAttr, - TestReadyConditionsInterval, + testReadyConditionsInterval, service_config.TimeoutAttr, - TestReadyConditionsTimeout, + testReadyConditionsTimeout, ) } @@ -59,14 +59,14 @@ func (t *readyConditionsHttpRecipeTestCase) Assert(typeValue builtin_argument.Ku if assert.Nil(t, err) { portId, ok := portIdAttrValue.(starlark.String) require.True(t, ok) - require.Equal(t, TestReadyConditionsRecipePortId, portId.GoString()) + require.Equal(t, testReadyConditionsRecipePortId, portId.GoString()) } endpointAttrValue, err := castedRecipe.Attr(recipe.EndpointAttr) if assert.Nil(t, err) { endpoint, ok := endpointAttrValue.(starlark.String) require.True(t, ok) - require.Equal(t, TestReadyConditionsRecipeEndpoint, endpoint.GoString()) + require.Equal(t, testReadyConditionsRecipeEndpoint, endpoint.GoString()) } extractAttrValue, err := castedRecipe.Attr(recipe.ExtractAttr) @@ -80,22 +80,22 @@ func (t *readyConditionsHttpRecipeTestCase) Assert(typeValue builtin_argument.Ku field, err := receivedReadyConditions.GetField() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsField, field) + require.Equal(t, testReadyConditionsField, field) } assertion, err := receivedReadyConditions.GetAssertion() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsAssertion, assertion) + require.Equal(t, testReadyConditionsAssertion, assertion) } target, err := receivedReadyConditions.GetTarget() if assert.Nil(t, err) { - require.Equal(t, TestReadyConditionsTarget, target.String()) + require.Equal(t, testReadyConditionsTarget, target.String()) } interval, err := receivedReadyConditions.GetInterval() if assert.Nil(t, err) { - expectedInterval, err := time.ParseDuration(TestReadyConditionsInterval) + expectedInterval, err := time.ParseDuration(testReadyConditionsInterval) if assert.Nil(t, err) { require.Equal(t, expectedInterval, interval) } @@ -103,7 +103,7 @@ func (t *readyConditionsHttpRecipeTestCase) Assert(typeValue builtin_argument.Ku timeout, err := receivedReadyConditions.GetTimeout() if assert.Nil(t, err) { - expectedTimeout, err := time.ParseDuration(TestReadyConditionsTimeout) + expectedTimeout, err := time.ParseDuration(testReadyConditionsTimeout) if assert.Nil(t, err) { require.Equal(t, expectedTimeout, timeout) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/remove_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/remove_service_framework_test.go index 0f9b357c33..cacd604278 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/remove_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/remove_service_framework_test.go @@ -19,9 +19,9 @@ type removeServiceTestCase struct { func (suite *KurtosisPlanInstructionTestSuite) TestRemoveService() { suite.serviceNetwork.EXPECT().RemoveService( mock.Anything, - string(TestServiceName), + string(testServiceName), ).Times(1).Return( - TestServiceUuid, + testServiceUuid, nil, ) @@ -36,7 +36,7 @@ func (t *removeServiceTestCase) GetInstruction() *kurtosis_plan_instruction.Kurt } func (t *removeServiceTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", remove_service.RemoveServiceBuiltinName, remove_service.ServiceNameArgName, TestServiceName) + return fmt.Sprintf("%s(%s=%q)", remove_service.RemoveServiceBuiltinName, remove_service.ServiceNameArgName, testServiceName) } func (t *removeServiceTestCase) GetStarlarkCodeForAssertion() string { @@ -46,6 +46,6 @@ func (t *removeServiceTestCase) GetStarlarkCodeForAssertion() string { func (t *removeServiceTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.None, interpretationResult) - expectedExecutionResult := fmt.Sprintf("Service '%s' with service UUID '%s' removed", TestServiceName, TestServiceUuid) + expectedExecutionResult := fmt.Sprintf("Service '%s' with service UUID '%s' removed", testServiceName, testServiceUuid) require.Regexp(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go index 66fb51dc85..7755a0c73a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_multiple_templates_framework_test.go @@ -48,7 +48,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestRenderMultipleTemplates() { nil, ) - suite.serviceNetwork.EXPECT().RenderTemplates(templatesAndData, mockedFileArtifactName).Times(1).Return(TestArtifactUuid, nil) + suite.serviceNetwork.EXPECT().RenderTemplates(templatesAndData, mockedFileArtifactName).Times(1).Return(testArtifactUuid, nil) suite.run(&renderMultipleTemplatesTestCase{ T: suite.T(), @@ -73,7 +73,7 @@ func (t *renderMultipleTemplatesTestCase) GetStarlarkCodeForAssertion() string { func (t *renderMultipleTemplatesTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.String(mockedFileArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Templates artifact name '%v' rendered with artifact UUID '%s'", mockedFileArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Templates artifact name '%v' rendered with artifact UUID '%s'", mockedFileArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) // no need to check for the mocked method as we set `.Times(1)` when we declared it diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go index 373a1ac438..a5fd1b6197 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/render_single_templates_framework_test.go @@ -34,7 +34,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestRenderSingleTemplate() { renderTemplate_SingleTemplate_filePath: templateData, } - suite.serviceNetwork.EXPECT().RenderTemplates(templateAndData, TestArtifactName).Times(1).Return(TestArtifactUuid, nil) + suite.serviceNetwork.EXPECT().RenderTemplates(templateAndData, testArtifactName).Times(1).Return(testArtifactUuid, nil) suite.run(&renderSingleTemplateTestCase{ T: suite.T(), @@ -49,7 +49,7 @@ func (t *renderSingleTemplateTestCase) GetInstruction() *kurtosis_plan_instructi func (t *renderSingleTemplateTestCase) GetStarlarkCode() string { configValue := fmt.Sprintf(`{%q: struct(data=%q, template=%q)}`, renderTemplate_SingleTemplate_filePath, renderTemplate_SingleTemplate_data, renderTemplate_SingleTemplate_template) - return fmt.Sprintf(`%s(%s=%s, %s=%q)`, render_templates.RenderTemplatesBuiltinName, render_templates.TemplateAndDataByDestinationRelFilepathArg, configValue, render_templates.ArtifactNameArgName, TestArtifactName) + return fmt.Sprintf(`%s(%s=%s, %s=%q)`, render_templates.RenderTemplatesBuiltinName, render_templates.TemplateAndDataByDestinationRelFilepathArg, configValue, render_templates.ArtifactNameArgName, testArtifactName) } func (t *renderSingleTemplateTestCase) GetStarlarkCodeForAssertion() string { @@ -57,9 +57,9 @@ func (t *renderSingleTemplateTestCase) GetStarlarkCodeForAssertion() string { } func (t *renderSingleTemplateTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { - require.Equal(t, starlark.String(TestArtifactName), interpretationResult) + require.Equal(t, starlark.String(testArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Templates artifact name '%s' rendered with artifact UUID '%s'", TestArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Templates artifact name '%s' rendered with artifact UUID '%s'", testArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) // no need to check for the mocked method as we set `.Times(1)` when we declared it diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_backward_compatible_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_backward_compatible_test.go index 983dfd11fe..2b048d5751 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_backward_compatible_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_backward_compatible_test.go @@ -31,16 +31,16 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigFullBackwardComp func (t *serviceConfigFullTestCaseBackwardCompatible) GetStarlarkCode() string { starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%s)", service_config.ServiceConfigTypeName, - service_config.ImageAttr, TestContainerImageName, - service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", TestPrivatePortId, TestPrivatePortNumber, TestPrivatePortProtocolStr, TestPrivateApplicationProtocol, TestWaitConfiguration), - service_config.PublicPortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", TestPublicPortId, TestPublicPortNumber, TestPublicPortProtocolStr, TestPublicApplicationProtocol, TestWaitConfiguration), - service_config.FilesAttr, fmt.Sprintf("{%q: %q, %q: %q}", TestFilesArtifactPath1, TestFilesArtifactName1, TestFilesArtifactPath2, TestFilesArtifactName2), - service_config.EntrypointAttr, fmt.Sprintf("[%q, %q]", TestEntryPointSlice[0], TestEntryPointSlice[1]), - service_config.CmdAttr, fmt.Sprintf("[%q, %q, %q]", TestCmdSlice[0], TestCmdSlice[1], TestCmdSlice[2]), - service_config.EnvVarsAttr, fmt.Sprintf("{%q: %q, %q: %q}", TestEnvVarName1, TestEnvVarValue1, TestEnvVarName2, TestEnvVarValue2), - service_config.PrivateIpAddressPlaceholderAttr, TestPrivateIPAddressPlaceholder, - service_config.CpuAllocationAttr, TestCpuAllocation, - service_config.MemoryAllocationAttr, TestMemoryAllocation, + service_config.ImageAttr, testContainerImageName, + service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPrivatePortId, testPrivatePortNumber, testPrivatePortProtocolStr, testPrivateApplicationProtocol, testWaitConfiguration), + service_config.PublicPortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPublicPortId, testPublicPortNumber, testPublicPortProtocolStr, testPublicApplicationProtocol, testWaitConfiguration), + service_config.FilesAttr, fmt.Sprintf("{%q: %q, %q: %q}", testFilesArtifactPath1, testFilesArtifactName1, testFilesArtifactPath2, testFilesArtifactName2), + service_config.EntrypointAttr, fmt.Sprintf("[%q, %q]", testEntryPointSlice[0], testEntryPointSlice[1]), + service_config.CmdAttr, fmt.Sprintf("[%q, %q, %q]", testCmdSlice[0], testCmdSlice[1], testCmdSlice[2]), + service_config.EnvVarsAttr, fmt.Sprintf("{%q: %q, %q: %q}", testEnvVarName1, testEnvVarValue1, testEnvVarName2, testEnvVarValue2), + service_config.PrivateIpAddressPlaceholderAttr, testPrivateIPAddressPlaceholder, + service_config.CpuAllocationAttr, testCpuAllocation, + service_config.MemoryAllocationAttr, testMemoryAllocation, service_config.ReadyConditionsAttr, getDefaultReadyConditionsScriptPart(), ) @@ -54,44 +54,44 @@ func (t *serviceConfigFullTestCaseBackwardCompatible) Assert(typeValue builtin_a serviceConfig, err := serviceConfigStarlark.ToKurtosisType(t.serviceNetwork) require.Nil(t, err) - require.Equal(t, TestContainerImageName, serviceConfig.GetContainerImageName()) + require.Equal(t, testContainerImageName, serviceConfig.GetContainerImageName()) - waitDuration, errParseDuration := time.ParseDuration(TestWaitConfiguration) + waitDuration, errParseDuration := time.ParseDuration(testWaitConfiguration) require.NoError(t, errParseDuration) - privatePortSpec, errPrivatePortSpec := port_spec.NewPortSpec(TestPrivatePortNumber, TestPrivatePortProtocol, TestPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) + privatePortSpec, errPrivatePortSpec := port_spec.NewPortSpec(testPrivatePortNumber, testPrivatePortProtocol, testPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) require.NoError(t, errPrivatePortSpec) expectedPrivatePorts := map[string]*port_spec.PortSpec{ - TestPrivatePortId: privatePortSpec, + testPrivatePortId: privatePortSpec, } require.Equal(t, expectedPrivatePorts, serviceConfig.GetPrivatePorts()) - portSpec, errPublicPortSpec := port_spec.NewPortSpec(TestPublicPortNumber, TestPublicPortProtocol, TestPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) + portSpec, errPublicPortSpec := port_spec.NewPortSpec(testPublicPortNumber, testPublicPortProtocol, testPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) require.NoError(t, errPublicPortSpec) expectedPublicPorts := map[string]*port_spec.PortSpec{ - TestPublicPortId: portSpec, + testPublicPortId: portSpec, } require.Equal(t, expectedPublicPorts, serviceConfig.GetPublicPorts()) expectedFilesArtifactMap := map[string]string{ - TestFilesArtifactPath1: TestFilesArtifactName1, - TestFilesArtifactPath2: TestFilesArtifactName2, + testFilesArtifactPath1: testFilesArtifactName1, + testFilesArtifactPath2: testFilesArtifactName2, } require.NotNil(t, serviceConfig.GetFilesArtifactsExpansion()) require.Equal(t, expectedFilesArtifactMap, serviceConfig.GetFilesArtifactsExpansion().ServiceDirpathsToArtifactIdentifiers) - require.Equal(t, TestEntryPointSlice, serviceConfig.GetEntrypointArgs()) - require.Equal(t, TestCmdSlice, serviceConfig.GetCmdArgs()) + require.Equal(t, testEntryPointSlice, serviceConfig.GetEntrypointArgs()) + require.Equal(t, testCmdSlice, serviceConfig.GetCmdArgs()) expectedEnvVars := map[string]string{ - TestEnvVarName1: TestEnvVarValue1, - TestEnvVarName2: TestEnvVarValue2, + testEnvVarName1: testEnvVarValue1, + testEnvVarName2: testEnvVarValue2, } require.Equal(t, expectedEnvVars, serviceConfig.GetEnvVars()) - require.Equal(t, TestPrivateIPAddressPlaceholder, serviceConfig.GetPrivateIPAddrPlaceholder()) - require.Equal(t, TestMemoryAllocation, serviceConfig.GetMemoryAllocationMegabytes()) - require.Equal(t, TestCpuAllocation, serviceConfig.GetCPUAllocationMillicpus()) + require.Equal(t, testPrivateIPAddressPlaceholder, serviceConfig.GetPrivateIPAddrPlaceholder()) + require.Equal(t, testMemoryAllocation, serviceConfig.GetMemoryAllocationMegabytes()) + require.Equal(t, testCpuAllocation, serviceConfig.GetCPUAllocationMillicpus()) require.Equal(t, uint64(0), serviceConfig.GetMinMemoryAllocationMegabytes()) require.Equal(t, uint64(0), serviceConfig.GetMinCPUAllocationMillicpus()) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go index 5bb858f8e6..72577f11cc 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_full_framework_test.go @@ -31,23 +31,23 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigFull() { } func (t *serviceConfigFullTestCase) GetStarlarkCode() string { - fileArtifact1 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, TestFilesArtifactName1) - fileArtifact2 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, TestFilesArtifactName2) - persistentDirectory := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, TestPersistentDirectoryKey) + fileArtifact1 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, testFilesArtifactName1) + fileArtifact2 := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.ArtifactNameAttr, testFilesArtifactName2) + persistentDirectory := fmt.Sprintf("%s(%s=%q)", directory.DirectoryTypeName, directory.PersistentKeyAttr, testPersistentDirectoryKey) starlarkCode := fmt.Sprintf("%s(%s=%q, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%s, %s=%q, %s=%d, %s=%d, %s=%d, %s=%d, %s=%s)", service_config.ServiceConfigTypeName, - service_config.ImageAttr, TestContainerImageName, - service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", TestPrivatePortId, TestPrivatePortNumber, TestPrivatePortProtocolStr, TestPrivateApplicationProtocol, TestWaitConfiguration), - service_config.PublicPortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", TestPublicPortId, TestPublicPortNumber, TestPublicPortProtocolStr, TestPublicApplicationProtocol, TestWaitConfiguration), - service_config.FilesAttr, fmt.Sprintf("{%q: %s, %q: %s, %q: %s}", TestFilesArtifactPath1, fileArtifact1, TestFilesArtifactPath2, fileArtifact2, TestPersistentDirectoryPath, persistentDirectory), - service_config.EntrypointAttr, fmt.Sprintf("[%q, %q]", TestEntryPointSlice[0], TestEntryPointSlice[1]), - service_config.CmdAttr, fmt.Sprintf("[%q, %q, %q]", TestCmdSlice[0], TestCmdSlice[1], TestCmdSlice[2]), - service_config.EnvVarsAttr, fmt.Sprintf("{%q: %q, %q: %q}", TestEnvVarName1, TestEnvVarValue1, TestEnvVarName2, TestEnvVarValue2), - service_config.PrivateIpAddressPlaceholderAttr, TestPrivateIPAddressPlaceholder, - service_config.MaxCpuMilliCoresAttr, TestCpuAllocation, - service_config.MinCpuMilliCoresAttr, TestMinCpuMilliCores, - service_config.MaxMemoryMegaBytesAttr, TestMemoryAllocation, - service_config.MinMemoryMegaBytesAttr, TestMinMemoryMegabytes, + service_config.ImageAttr, testContainerImageName, + service_config.PortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPrivatePortId, testPrivatePortNumber, testPrivatePortProtocolStr, testPrivateApplicationProtocol, testWaitConfiguration), + service_config.PublicPortsAttr, fmt.Sprintf("{%q: PortSpec(number=%d, transport_protocol=%q, application_protocol=%q, wait=%q)}", testPublicPortId, testPublicPortNumber, testPublicPortProtocolStr, testPublicApplicationProtocol, testWaitConfiguration), + service_config.FilesAttr, fmt.Sprintf("{%q: %s, %q: %s, %q: %s}", testFilesArtifactPath1, fileArtifact1, testFilesArtifactPath2, fileArtifact2, testPersistentDirectoryPath, persistentDirectory), + service_config.EntrypointAttr, fmt.Sprintf("[%q, %q]", testEntryPointSlice[0], testEntryPointSlice[1]), + service_config.CmdAttr, fmt.Sprintf("[%q, %q, %q]", testCmdSlice[0], testCmdSlice[1], testCmdSlice[2]), + service_config.EnvVarsAttr, fmt.Sprintf("{%q: %q, %q: %q}", testEnvVarName1, testEnvVarValue1, testEnvVarName2, testEnvVarValue2), + service_config.PrivateIpAddressPlaceholderAttr, testPrivateIPAddressPlaceholder, + service_config.MaxCpuMilliCoresAttr, testCpuAllocation, + service_config.MinCpuMilliCoresAttr, testMinCpuMilliCores, + service_config.MaxMemoryMegaBytesAttr, testMemoryAllocation, + service_config.MinMemoryMegaBytesAttr, testMinMemoryMegabytes, service_config.ReadyConditionsAttr, getDefaultReadyConditionsScriptPart(), ) @@ -61,50 +61,50 @@ func (t *serviceConfigFullTestCase) Assert(typeValue builtin_argument.KurtosisVa serviceConfig, err := serviceConfigStarlark.ToKurtosisType(t.serviceNetwork) require.Nil(t, err) - require.Equal(t, TestContainerImageName, serviceConfig.GetContainerImageName()) + require.Equal(t, testContainerImageName, serviceConfig.GetContainerImageName()) - waitDuration, errParseDuration := time.ParseDuration(TestWaitConfiguration) + waitDuration, errParseDuration := time.ParseDuration(testWaitConfiguration) require.NoError(t, errParseDuration) - privatePortSpec, errPrivatePortSpec := port_spec.NewPortSpec(TestPrivatePortNumber, TestPrivatePortProtocol, TestPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) + privatePortSpec, errPrivatePortSpec := port_spec.NewPortSpec(testPrivatePortNumber, testPrivatePortProtocol, testPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) require.NoError(t, errPrivatePortSpec) expectedPrivatePorts := map[string]*port_spec.PortSpec{ - TestPrivatePortId: privatePortSpec, + testPrivatePortId: privatePortSpec, } require.Equal(t, expectedPrivatePorts, serviceConfig.GetPrivatePorts()) - portSpec, errPublicPortSpec := port_spec.NewPortSpec(TestPublicPortNumber, TestPublicPortProtocol, TestPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) + portSpec, errPublicPortSpec := port_spec.NewPortSpec(testPublicPortNumber, testPublicPortProtocol, testPrivateApplicationProtocol, port_spec.NewWait(waitDuration)) require.NoError(t, errPublicPortSpec) expectedPublicPorts := map[string]*port_spec.PortSpec{ - TestPublicPortId: portSpec, + testPublicPortId: portSpec, } require.Equal(t, expectedPublicPorts, serviceConfig.GetPublicPorts()) expectedFilesArtifactMap := map[string]string{ - TestFilesArtifactPath1: TestFilesArtifactName1, - TestFilesArtifactPath2: TestFilesArtifactName2, + testFilesArtifactPath1: testFilesArtifactName1, + testFilesArtifactPath2: testFilesArtifactName2, } require.NotNil(t, serviceConfig.GetFilesArtifactsExpansion()) require.Equal(t, expectedFilesArtifactMap, serviceConfig.GetFilesArtifactsExpansion().ServiceDirpathsToArtifactIdentifiers) expectedPersistentDirectoryMap := map[string]service_directory.DirectoryPersistentKey{ - TestPersistentDirectoryPath: service_directory.DirectoryPersistentKey(TestPersistentDirectoryKey), + testPersistentDirectoryPath: service_directory.DirectoryPersistentKey(testPersistentDirectoryKey), } require.NotNil(t, serviceConfig.GetPersistentDirectories()) require.Equal(t, expectedPersistentDirectoryMap, serviceConfig.GetPersistentDirectories().ServiceDirpathToDirectoryPersistentKey) - require.Equal(t, TestEntryPointSlice, serviceConfig.GetEntrypointArgs()) - require.Equal(t, TestCmdSlice, serviceConfig.GetCmdArgs()) + require.Equal(t, testEntryPointSlice, serviceConfig.GetEntrypointArgs()) + require.Equal(t, testCmdSlice, serviceConfig.GetCmdArgs()) expectedEnvVars := map[string]string{ - TestEnvVarName1: TestEnvVarValue1, - TestEnvVarName2: TestEnvVarValue2, + testEnvVarName1: testEnvVarValue1, + testEnvVarName2: testEnvVarValue2, } require.Equal(t, expectedEnvVars, serviceConfig.GetEnvVars()) - require.Equal(t, TestPrivateIPAddressPlaceholder, serviceConfig.GetPrivateIPAddrPlaceholder()) - require.Equal(t, TestMemoryAllocation, serviceConfig.GetMemoryAllocationMegabytes()) - require.Equal(t, TestCpuAllocation, serviceConfig.GetCPUAllocationMillicpus()) - require.Equal(t, TestMinMemoryMegabytes, serviceConfig.GetMinMemoryAllocationMegabytes()) - require.Equal(t, TestMinCpuMilliCores, serviceConfig.GetMinCPUAllocationMillicpus()) + require.Equal(t, testPrivateIPAddressPlaceholder, serviceConfig.GetPrivateIPAddrPlaceholder()) + require.Equal(t, testMemoryAllocation, serviceConfig.GetMemoryAllocationMegabytes()) + require.Equal(t, testCpuAllocation, serviceConfig.GetCPUAllocationMillicpus()) + require.Equal(t, testMinMemoryMegabytes, serviceConfig.GetMinMemoryAllocationMegabytes()) + require.Equal(t, testMinCpuMilliCores, serviceConfig.GetMinCPUAllocationMillicpus()) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go index 0a8aac3ec5..538fe735ee 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_config_minimal_framework_test.go @@ -26,7 +26,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceConfigMinimal() { func (t *serviceConfigMinimalTestCase) GetStarlarkCode() string { return fmt.Sprintf("%s(%s=%q)", service_config.ServiceConfigTypeName, - service_config.ImageAttr, TestContainerImageName) + service_config.ImageAttr, testContainerImageName) } func (t *serviceConfigMinimalTestCase) Assert(typeValue builtin_argument.KurtosisValueType) { @@ -37,7 +37,7 @@ func (t *serviceConfigMinimalTestCase) Assert(typeValue builtin_argument.Kurtosi require.Nil(t, err) expectedServiceConfig := service.NewServiceConfig( - TestContainerImageName, + testContainerImageName, map[string]*port_spec.PortSpec{}, map[string]*port_spec.PortSpec{}, nil, diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_framework_test.go index d494e0cb7e..1b9908ad3a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/service_framework_test.go @@ -27,7 +27,7 @@ func (suite *KurtosisTypeConstructorTestSuite) TestServiceObject() { func (t serviceObjectTestCase) GetStarlarkCode() string { return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q, %s=%s)", kurtosis_types.ServiceTypeName, - kurtosis_types.ServiceNameAttr, TestServiceName, + kurtosis_types.ServiceNameAttr, testServiceName, kurtosis_types.HostnameAttr, testServiceHostname, kurtosis_types.IpAddressAttr, testServiceIpAddress, kurtosis_types.PortsAttr, testServicePorts) @@ -39,7 +39,7 @@ func (t serviceObjectTestCase) Assert(typeValue builtin_argument.KurtosisValueTy resultServiceName, interpretationErr := serviceStarlark.GetName() require.Nil(t, interpretationErr) - require.Equal(t, TestServiceName, resultServiceName) + require.Equal(t, testServiceName, resultServiceName) resultServiceHostname, interpretationErr := serviceStarlark.GetHostname() require.Nil(t, interpretationErr) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/shared_functions.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/shared_functions.go index 5636831211..19803228da 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/shared_functions.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/shared_functions.go @@ -8,14 +8,14 @@ import ( func getDefaultReadyConditionsScriptPart() string { return getCustomReadyConditionsScripPart( - TestReadyConditionsRecipePortId, - TestReadyConditionsRecipeEndpoint, - TestReadyConditionsRecipeExtract, - TestReadyConditionsField, - TestReadyConditionsAssertion, - TestReadyConditionsTarget, - TestReadyConditionsInterval, - TestReadyConditionsTimeout, + testReadyConditionsRecipePortId, + testReadyConditionsRecipeEndpoint, + testReadyConditionsRecipeExtract, + testReadyConditionsField, + testReadyConditionsAssertion, + testReadyConditionsTarget, + testReadyConditionsInterval, + testReadyConditionsTimeout, ) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/start_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/start_service_framework_test.go index c41b46dc0f..085315b66f 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/start_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/start_service_framework_test.go @@ -19,7 +19,7 @@ type startServiceTestCase struct { func (suite *KurtosisPlanInstructionTestSuite) TestStartService() { suite.serviceNetwork.EXPECT().StartService( mock.Anything, - string(TestServiceName), + string(testServiceName), ).Times(1).Return( nil, ) @@ -35,7 +35,7 @@ func (t *startServiceTestCase) GetInstruction() *kurtosis_plan_instruction.Kurto } func (t *startServiceTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", start_service.StartServiceBuiltinName, start_service.ServiceNameArgName, TestServiceName) + return fmt.Sprintf("%s(%s=%q)", start_service.StartServiceBuiltinName, start_service.ServiceNameArgName, testServiceName) } func (t *startServiceTestCase) GetStarlarkCodeForAssertion() string { @@ -45,6 +45,6 @@ func (t *startServiceTestCase) GetStarlarkCodeForAssertion() string { func (t *startServiceTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.None, interpretationResult) - expectedExecutionResult := fmt.Sprintf("Service '%s' started", TestServiceName) + expectedExecutionResult := fmt.Sprintf("Service '%s' started", testServiceName) require.Regexp(t, expectedExecutionResult, *executionResult) } 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 f09444e473..7d407abcf6 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 @@ -9,88 +9,89 @@ import ( // nolint: gomnd var ( - TestEnclaveUuid = enclave.EnclaveUUID("test-enclave-uuid") - - TestServiceName = service.ServiceName("test-service-name") - TestServiceUuid = service.ServiceUUID("test-service-uuid") - TestServiceName2 = service.ServiceName("test-service-name-2") - TestServiceUuid2 = service.ServiceUUID("test-service-uuid-2") - - TestArtifactName = "artifact-name" - TestArtifactUuid = enclave_data_directory.FilesArtifactUUID("file-artifact-uuid") - - TestSrcPath = "/path/to/file.txt" - - TestModulePackageId = "github.com/kurtosistech/test-package" - TestModuleFileName = "github.com/kurtosistech/test-package/helpers.star" - TestModuleRelativeLocator = "./helpers.star" - TestModuleDirpath = "/kurtosistech/test-package" - - TestContainerImageName = "kurtosistech/example-datastore-server" - - TestPrivatePortId = "grpc" - TestPrivatePortNumber = uint16(1323) - TestPrivatePortProtocolStr = "TCP" - TestPrivatePortProtocol = port_spec.TransportProtocol_TCP - TestPrivateApplicationProtocol = "https" - TestWaitConfiguration = "2s" - TestWaitDefaultValue = "2m" - - TestPublicPortId = "endpoints" - TestPublicPortNumber = uint16(80) - TestPublicPortProtocolStr = "TCP" - TestPublicPortProtocol = port_spec.TransportProtocol_TCP - TestPublicApplicationProtocol = "https" - - TestFilesArtifactPath1 = "path/to/file/1" - TestFilesArtifactName1 = "file_1" - TestFilesArtifactPath2 = "path/to/file/2" - TestFilesArtifactName2 = "file_2" - TestPersistentDirectoryPath = "path/to/persistent/dir" - TestPersistentDirectoryKey = "persistent-dir-test" - - TestEntryPointSlice = []string{ + testEnclaveUuid = enclave.EnclaveUUID("test-enclave-uuid") + + testServiceName = service.ServiceName("test-service-name") + testServiceUuid = service.ServiceUUID("test-service-uuid") + testServiceName2 = service.ServiceName("test-service-name-2") + testServiceUuid2 = service.ServiceUUID("test-service-uuid-2") + + testArtifactName = "artifact-name" + testArtifactUuid = enclave_data_directory.FilesArtifactUUID("file-artifact-uuid") + + testSrcPath = "/path/to/file.txt" + + testModulePackageId = "github.com/kurtosistech/test-package" + testModuleFileName = "github.com/kurtosistech/test-package/helpers.star" + testModuleRelativeLocator = "./helpers.star" + + testContainerImageName = "kurtosistech/example-datastore-server" + + testPrivatePortId = "grpc" + testPrivatePortNumber = uint16(1323) + testPrivatePortProtocolStr = "TCP" + testPrivatePortProtocol = port_spec.TransportProtocol_TCP + testPrivateApplicationProtocol = "https" + testWaitConfiguration = "2s" + testWaitDefaultValue = "2m" + + testPublicPortId = "endpoints" + testPublicPortNumber = uint16(80) + testPublicPortProtocolStr = "TCP" + testPublicPortProtocol = port_spec.TransportProtocol_TCP + testPublicApplicationProtocol = "https" + + testFilesArtifactPath1 = "path/to/file/1" + testFilesArtifactName1 = "file_1" + testFilesArtifactPath2 = "path/to/file/2" + testFilesArtifactName2 = "file_2" + testPersistentDirectoryPath = "path/to/persistent/dir" + testPersistentDirectoryKey = "persistent-dir-test" + + testEntryPointSlice = []string{ "127.0.0.0", "1234", } - TestCmdSlice = []string{ + testCmdSlice = []string{ "bash", "-c", "/apps/main.py", } - TestEnvVarName1 = "VAR_1" - TestEnvVarValue1 = "VALUE_1" - TestEnvVarName2 = "VAR_2" - TestEnvVarValue2 = "VALUE_2" - - TestPrivateIPAddressPlaceholder = "" - - TestCpuAllocation = uint64(2000) - TestMemoryAllocation = uint64(1024) - - TestMinCpuMilliCores = uint64(1000) - TestMinMemoryMegabytes = uint64(512) - - TestReadyConditionsRecipePortId = "http" - TestReadyConditionsRecipeEndpoint = "/endpoint?input=data" - TestReadyConditionsRecipeCommand = []string{"tool", "arg"} - TestReadyConditionsRecipeExtract = "{}" - TestReadyConditionsField = "code" - TestReadyConditionsAssertion = "==" - TestReadyConditionsTarget = "200" - TestReadyConditionsInterval = "1s" - TestReadyConditionsTimeout = "100ms" - - TestReadyConditions2RecipePortId = "https" - TestReadyConditions2RecipeEndpoint = "/user-access" - TestReadyConditions2RecipeExtract = "{}" - TestReadyConditions2Field = "code" - TestReadyConditions2Assertion = "==" - TestReadyConditions2Target = "201" - TestReadyConditions2Interval = "500ms" - TestReadyConditions2Timeout = "2s" - - TestGetRequestMethod = "GET" + testEnvVarName1 = "VAR_1" + testEnvVarValue1 = "VALUE_1" + testEnvVarName2 = "VAR_2" + testEnvVarValue2 = "VALUE_2" + + testPrivateIPAddressPlaceholder = "" + + testCpuAllocation = uint64(2000) + testMemoryAllocation = uint64(1024) + + testMinCpuMilliCores = uint64(1000) + testMinMemoryMegabytes = uint64(512) + + testReadyConditionsRecipePortId = "http" + testReadyConditionsRecipeEndpoint = "/endpoint?input=data" + testReadyConditionsRecipeCommand = []string{"tool", "arg"} + testReadyConditionsRecipeExtract = "{}" + testReadyConditionsField = "code" + testReadyConditionsAssertion = "==" + testReadyConditionsTarget = "200" + testReadyConditionsInterval = "1s" + testReadyConditionsTimeout = "100ms" + + testReadyConditions2RecipePortId = "https" + testReadyConditions2RecipeEndpoint = "/user-access" + testReadyConditions2RecipeExtract = "{}" + testReadyConditions2Field = "code" + testReadyConditions2Assertion = "==" + testReadyConditions2Target = "201" + testReadyConditions2Interval = "500ms" + testReadyConditions2Timeout = "2s" + + testGetRequestMethod = "GET" + + testNoPackageReplaceOptions = map[string]string{} ) diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/stop_service_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/stop_service_framework_test.go index bd3dc52ccd..8da6746c31 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/stop_service_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/stop_service_framework_test.go @@ -19,7 +19,7 @@ type stopServiceTestCase struct { func (suite *KurtosisPlanInstructionTestSuite) TestStopService() { suite.serviceNetwork.EXPECT().StopService( mock.Anything, - string(TestServiceName), + string(testServiceName), ).Times(1).Return( nil, ) @@ -35,7 +35,7 @@ func (t *stopServiceTestCase) GetInstruction() *kurtosis_plan_instruction.Kurtos } func (t *stopServiceTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", stop_service.StopServiceBuiltinName, stop_service.ServiceNameArgName, TestServiceName) + return fmt.Sprintf("%s(%s=%q)", stop_service.StopServiceBuiltinName, stop_service.ServiceNameArgName, testServiceName) } func (t *stopServiceTestCase) GetStarlarkCodeForAssertion() string { @@ -45,6 +45,6 @@ func (t *stopServiceTestCase) GetStarlarkCodeForAssertion() string { func (t *stopServiceTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.None, interpretationResult) - expectedExecutionResult := fmt.Sprintf("Service '%s' stopped", TestServiceName) + expectedExecutionResult := fmt.Sprintf("Service '%s' stopped", testServiceName) require.Regexp(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_framework_test.go index 78bf6915bf..325807863c 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_framework_test.go @@ -19,11 +19,11 @@ type storeServiceFilesTestCase struct { func (suite *KurtosisPlanInstructionTestSuite) TestStoreServiceFiles() { suite.serviceNetwork.EXPECT().CopyFilesFromService( mock.Anything, - string(TestServiceName), - TestSrcPath, - TestArtifactName, + string(testServiceName), + testSrcPath, + testArtifactName, ).Times(1).Return( - TestArtifactUuid, + testArtifactUuid, nil, ) @@ -38,7 +38,7 @@ func (t *storeServiceFilesTestCase) GetInstruction() *kurtosis_plan_instruction. } func (t *storeServiceFilesTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q)", store_service_files.StoreServiceFilesBuiltinName, store_service_files.ServiceNameArgName, TestServiceName, store_service_files.SrcArgName, TestSrcPath, store_service_files.ArtifactNameArgName, TestArtifactName) + return fmt.Sprintf("%s(%s=%q, %s=%q, %s=%q)", store_service_files.StoreServiceFilesBuiltinName, store_service_files.ServiceNameArgName, testServiceName, store_service_files.SrcArgName, testSrcPath, store_service_files.ArtifactNameArgName, testArtifactName) } func (t *storeServiceFilesTestCase) GetStarlarkCodeForAssertion() string { @@ -46,8 +46,8 @@ func (t *storeServiceFilesTestCase) GetStarlarkCodeForAssertion() string { } func (t *storeServiceFilesTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { - require.Equal(t, starlark.String(TestArtifactName), interpretationResult) + require.Equal(t, starlark.String(testArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", TestArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", testArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_without_name_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_without_name_framework_test.go index 6dcd97758a..3560b5adc2 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_without_name_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/store_service_files_without_name_framework_test.go @@ -24,11 +24,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestStoreServiceFilesWithoutName( suite.serviceNetwork.EXPECT().CopyFilesFromService( mock.Anything, - string(TestServiceName), - TestSrcPath, + string(testServiceName), + testSrcPath, mockedFileArtifactName, ).Times(1).Return( - TestArtifactUuid, + testArtifactUuid, nil, ) @@ -43,7 +43,7 @@ func (t *storeServiceFilesWithoutNameTestCase) GetInstruction() *kurtosis_plan_i } func (t *storeServiceFilesWithoutNameTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", store_service_files.StoreServiceFilesBuiltinName, store_service_files.ServiceNameArgName, TestServiceName, store_service_files.SrcArgName, TestSrcPath) + return fmt.Sprintf("%s(%s=%q, %s=%q)", store_service_files.StoreServiceFilesBuiltinName, store_service_files.ServiceNameArgName, testServiceName, store_service_files.SrcArgName, testSrcPath) } func (t *storeServiceFilesWithoutNameTestCase) GetStarlarkCodeForAssertion() string { @@ -53,6 +53,6 @@ func (t *storeServiceFilesWithoutNameTestCase) GetStarlarkCodeForAssertion() str func (t *storeServiceFilesWithoutNameTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.String(mockedFileArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", mockedFileArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", mockedFileArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_framework_test.go index a57a741b12..a632fa9b70 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_framework_test.go @@ -20,10 +20,10 @@ type uploadFilesTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestUploadFiles() { - suite.Require().Nil(suite.packageContentProvider.AddFileContent(TestModuleFileName, "Hello World!")) + suite.Require().Nil(suite.packageContentProvider.AddFileContent(testModuleFileName, "Hello World!")) suite.serviceNetwork.EXPECT().GetFilesArtifactMd5( - TestArtifactName, + testArtifactName, ).Times(1).Return( enclave_data_directory.FilesArtifactUUID(""), nil, @@ -33,9 +33,9 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFiles() { suite.serviceNetwork.EXPECT().UploadFilesArtifact( mock.Anything, // data gets written to disk and compressed to it's a bit tricky to replicate here. mock.Anything, // and same for the hash - TestArtifactName, + testArtifactName, ).Times(1).Return( - TestArtifactUuid, + testArtifactUuid, nil, ) @@ -47,11 +47,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFiles() { } func (t *uploadFilesTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction { - return upload_files.NewUploadFiles(TestModulePackageId, t.serviceNetwork, t.packageContentProvider) + return upload_files.NewUploadFiles(testModulePackageId, t.serviceNetwork, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *uploadFilesTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, TestModuleRelativeLocator, upload_files.ArtifactNameArgName, TestArtifactName) + return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, testModuleRelativeLocator, upload_files.ArtifactNameArgName, testArtifactName) } func (t *uploadFilesTestCase) GetStarlarkCodeForAssertion() string { @@ -59,8 +59,8 @@ func (t *uploadFilesTestCase) GetStarlarkCodeForAssertion() string { } func (t *uploadFilesTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { - require.Equal(t, starlark.String(TestArtifactName), interpretationResult) + require.Equal(t, starlark.String(testArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", TestArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", testArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_update_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_update_framework_test.go index 58257b24a2..c04d920f6e 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_update_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_update_framework_test.go @@ -19,18 +19,18 @@ type uploadFilesUpdateTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesUpdate() { - suite.Require().Nil(suite.packageContentProvider.AddFileContent(TestModuleFileName, "Hello World!")) + suite.Require().Nil(suite.packageContentProvider.AddFileContent(testModuleFileName, "Hello World!")) suite.serviceNetwork.EXPECT().GetFilesArtifactMd5( - TestArtifactName, + testArtifactName, ).Times(1).Return( - TestArtifactUuid, + testArtifactUuid, []byte{}, true, nil, ) suite.serviceNetwork.EXPECT().UpdateFilesArtifact( - TestArtifactUuid, + testArtifactUuid, mock.Anything, // data gets written to disk and compressed to it's a bit tricky to replicate here. mock.Anything, // and same for the hash ).Times(1).Return( @@ -45,11 +45,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesUpdate() { } func (t *uploadFilesUpdateTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction { - return upload_files.NewUploadFiles(TestModulePackageId, t.serviceNetwork, t.packageContentProvider) + return upload_files.NewUploadFiles(testModulePackageId, t.serviceNetwork, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *uploadFilesUpdateTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, TestModuleRelativeLocator, upload_files.ArtifactNameArgName, TestArtifactName) + return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, testModuleRelativeLocator, upload_files.ArtifactNameArgName, testArtifactName) } func (t *uploadFilesUpdateTestCase) GetStarlarkCodeForAssertion() string { @@ -57,8 +57,8 @@ func (t *uploadFilesUpdateTestCase) GetStarlarkCodeForAssertion() string { } func (t *uploadFilesUpdateTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { - require.Equal(t, starlark.String(TestArtifactName), interpretationResult) + require.Equal(t, starlark.String(testArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' with artifact UUID '%s' updated", TestArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' with artifact UUID '%s' updated", testArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_with_local_absolute_locator_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_with_local_absolute_locator_framework_test.go index fb15044615..2a4ac1557a 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_with_local_absolute_locator_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_with_local_absolute_locator_framework_test.go @@ -21,7 +21,7 @@ type uploadFilesWithLocalAbsoluteLocatorTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesWithLocalAbsoluteLocatorShouldNotBeValid() { - suite.Require().Nil(suite.packageContentProvider.AddFileContent(TestModuleFileName, "Hello World!")) + suite.Require().Nil(suite.packageContentProvider.AddFileContent(testModuleFileName, "Hello World!")) suite.runShouldFail( &uploadFilesWithLocalAbsoluteLocatorTestCase{ @@ -34,11 +34,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesWithLocalAbsoluteL } func (t *uploadFilesWithLocalAbsoluteLocatorTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction { - return upload_files.NewUploadFiles(TestModulePackageId, t.serviceNetwork, t.packageContentProvider) + return upload_files.NewUploadFiles(testModulePackageId, t.serviceNetwork, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *uploadFilesWithLocalAbsoluteLocatorTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, TestModuleFileName, upload_files.ArtifactNameArgName, TestArtifactName) + return fmt.Sprintf("%s(%s=%q, %s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, testModuleFileName, upload_files.ArtifactNameArgName, testArtifactName) } func (t *uploadFilesWithLocalAbsoluteLocatorTestCase) GetStarlarkCodeForAssertion() string { diff --git a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_without_name_framework_test.go b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_without_name_framework_test.go index 5bbdb3b157..3530db1f9f 100644 --- a/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_without_name_framework_test.go +++ b/core/server/api_container/server/startosis_engine/kurtosis_starlark_framework/test_engine/upload_files_without_name_framework_test.go @@ -20,7 +20,7 @@ type uploadFilesWithoutNameTestCase struct { } func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesWithoutName() { - suite.Require().Nil(suite.packageContentProvider.AddFileContent(TestModuleFileName, "Hello World!")) + suite.Require().Nil(suite.packageContentProvider.AddFileContent(testModuleFileName, "Hello World!")) suite.serviceNetwork.EXPECT().GetUniqueNameForFileArtifact().Times(1).Return( mockedFileArtifactName, @@ -40,7 +40,7 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesWithoutName() { mock.Anything, // and same for the hash mockedFileArtifactName, ).Times(1).Return( - TestArtifactUuid, + testArtifactUuid, nil, ) @@ -52,11 +52,11 @@ func (suite *KurtosisPlanInstructionTestSuite) TestUploadFilesWithoutName() { } func (t *uploadFilesWithoutNameTestCase) GetInstruction() *kurtosis_plan_instruction.KurtosisPlanInstruction { - return upload_files.NewUploadFiles(TestModulePackageId, t.serviceNetwork, t.packageContentProvider) + return upload_files.NewUploadFiles(testModulePackageId, t.serviceNetwork, t.packageContentProvider, testNoPackageReplaceOptions) } func (t *uploadFilesWithoutNameTestCase) GetStarlarkCode() string { - return fmt.Sprintf("%s(%s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, TestModuleRelativeLocator) + return fmt.Sprintf("%s(%s=%q)", upload_files.UploadFilesBuiltinName, upload_files.SrcArgName, testModuleRelativeLocator) } func (t *uploadFilesWithoutNameTestCase) GetStarlarkCodeForAssertion() string { @@ -66,6 +66,6 @@ func (t *uploadFilesWithoutNameTestCase) GetStarlarkCodeForAssertion() string { func (t *uploadFilesWithoutNameTestCase) Assert(interpretationResult starlark.Value, executionResult *string) { require.Equal(t, starlark.String(mockedFileArtifactName), interpretationResult) - expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", mockedFileArtifactName, TestArtifactUuid) + expectedExecutionResult := fmt.Sprintf("Files with artifact name '%s' uploaded with artifact UUID '%s'", mockedFileArtifactName, testArtifactUuid) require.Equal(t, expectedExecutionResult, *executionResult) } diff --git a/core/server/api_container/server/startosis_engine/startosis_interpreter.go b/core/server/api_container/server/startosis_engine/startosis_interpreter.go index 9821cda6c4..3d19be23db 100644 --- a/core/server/api_container/server/startosis_engine/startosis_interpreter.go +++ b/core/server/api_container/server/startosis_engine/startosis_interpreter.go @@ -85,6 +85,7 @@ func NewStartosisInterpreter(serviceNetwork service_network.ServiceNetwork, modu func (interpreter *StartosisInterpreter) InterpretAndOptimizePlan( ctx context.Context, packageId string, + packageReplaceOptions map[string]string, mainFunctionName string, relativePathtoMainFile string, serializedStarlark string, @@ -95,7 +96,7 @@ func (interpreter *StartosisInterpreter) InterpretAndOptimizePlan( // run interpretation with no mask at all to generate the list of instructions as if the enclave was empty enclaveComponents := enclave_structure.NewEnclaveComponents() emptyPlanInstructionsMask := resolver.NewInstructionsPlanMask(0) - naiveInstructionsPlanSerializedScriptOutput, naiveInstructionsPlan, interpretationErrorApi := interpreter.Interpret(ctx, packageId, mainFunctionName, relativePathtoMainFile, serializedStarlark, serializedJsonParams, enclaveComponents, emptyPlanInstructionsMask) + naiveInstructionsPlanSerializedScriptOutput, naiveInstructionsPlan, interpretationErrorApi := interpreter.Interpret(ctx, packageId, mainFunctionName, packageReplaceOptions, relativePathtoMainFile, serializedStarlark, serializedJsonParams, enclaveComponents, emptyPlanInstructionsMask) if interpretationErrorApi != nil { return startosis_constants.NoOutputObject, nil, interpretationErrorApi } @@ -165,7 +166,7 @@ func (interpreter *StartosisInterpreter) InterpretAndOptimizePlan( } // Now that we have a potential plan mask, try running interpretation again using this plan mask - attemptSerializedScriptOutput, attemptInstructionsPlan, interpretationErrorApi := interpreter.Interpret(ctx, packageId, mainFunctionName, relativePathtoMainFile, serializedStarlark, serializedJsonParams, enclaveComponents, potentialMask) + attemptSerializedScriptOutput, attemptInstructionsPlan, interpretationErrorApi := interpreter.Interpret(ctx, packageId, mainFunctionName, packageReplaceOptions, relativePathtoMainFile, serializedStarlark, serializedJsonParams, enclaveComponents, potentialMask) if interpretationErrorApi != nil { // Note: there's no real reason why this interpretation would fail with an error, given that the package // has been interpreted once already (right above). But to be on the safe side, check the error @@ -209,6 +210,7 @@ func (interpreter *StartosisInterpreter) Interpret( _ context.Context, packageId string, mainFunctionName string, + packageReplaceOptions map[string]string, relativePathtoMainFile string, serializedStarlark string, serializedJsonParams string, @@ -226,7 +228,7 @@ func (interpreter *StartosisInterpreter) Interpret( // we use a new cache for every interpretation b/c the content of the module might have changed moduleGlobalCache := map[string]*startosis_packages.ModuleCacheEntry{} - globalVariables, interpretationErr := interpreter.interpretInternal(packageId, moduleLocator, serializedStarlark, newInstructionsPlan, moduleGlobalCache) + globalVariables, interpretationErr := interpreter.interpretInternal(packageId, moduleLocator, serializedStarlark, newInstructionsPlan, moduleGlobalCache, packageReplaceOptions) if interpretationErr != nil { return startosis_constants.NoOutputObject, nil, interpretationErr.ToAPIType() } @@ -262,7 +264,7 @@ func (interpreter *StartosisInterpreter) Interpret( if mainFuncParamsNum >= minimumParamsRequiredForPlan { firstParamName, _ := mainFunction.Param(planParamIndex) if firstParamName == planParamName { - kurtosisPlanInstructions := KurtosisPlanInstructions(packageId, interpreter.serviceNetwork, interpreter.recipeExecutor, interpreter.moduleContentProvider) + kurtosisPlanInstructions := KurtosisPlanInstructions(packageId, interpreter.serviceNetwork, interpreter.recipeExecutor, interpreter.moduleContentProvider, packageReplaceOptions) planModule := plan_module.PlanModule(newInstructionsPlan, enclaveComponents, interpreter.starlarkValueSerde, instructionsPlanMask, kurtosisPlanInstructions) argsTuple = append(argsTuple, planModule) } @@ -312,12 +314,19 @@ func (interpreter *StartosisInterpreter) Interpret( return startosis_constants.NoOutputObject, newInstructionsPlan, nil } -func (interpreter *StartosisInterpreter) interpretInternal(packageId string, moduleLocator string, serializedStarlark string, instructionPlan *instructions_plan.InstructionsPlan, moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry) (starlark.StringDict, *startosis_errors.InterpretationError) { +func (interpreter *StartosisInterpreter) interpretInternal( + packageId string, + moduleLocator string, + serializedStarlark string, + instructionPlan *instructions_plan.InstructionsPlan, + moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry, + packageReplaceOptions map[string]string, +) (starlark.StringDict, *startosis_errors.InterpretationError) { // We spin up a new thread for every call to interpreterInternal such that the stacktrace provided by the Starlark // Go interpreter is relative to each individual thread, and we don't keep accumulating stacktrace entries from the // previous calls inside the same thread thread := newStarlarkThread(moduleLocator) - predeclared, interpretationErr := interpreter.buildBindings(packageId, thread, instructionPlan, moduleGlobalCache) + predeclared, interpretationErr := interpreter.buildBindings(packageId, thread, instructionPlan, moduleGlobalCache, packageReplaceOptions) if interpretationErr != nil { return nil, interpretationErr } @@ -330,9 +339,15 @@ func (interpreter *StartosisInterpreter) interpretInternal(packageId string, mod return globalVariables, nil } -func (interpreter *StartosisInterpreter) buildBindings(packageId string, thread *starlark.Thread, instructionPlan *instructions_plan.InstructionsPlan, moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry) (*starlark.StringDict, *startosis_errors.InterpretationError) { +func (interpreter *StartosisInterpreter) buildBindings( + packageId string, + thread *starlark.Thread, + instructionPlan *instructions_plan.InstructionsPlan, + moduleGlobalCache map[string]*startosis_packages.ModuleCacheEntry, + packageReplaceOptions map[string]string, +) (*starlark.StringDict, *startosis_errors.InterpretationError) { recursiveInterpretForModuleLoading := func(moduleId string, serializedStartosis string) (starlark.StringDict, *startosis_errors.InterpretationError) { - result, err := interpreter.interpretInternal(packageId, moduleId, serializedStartosis, instructionPlan, moduleGlobalCache) + result, err := interpreter.interpretInternal(packageId, moduleId, serializedStartosis, instructionPlan, moduleGlobalCache, packageReplaceOptions) if err != nil { return nil, err } @@ -349,7 +364,7 @@ func (interpreter *StartosisInterpreter) buildBindings(packageId string, thread predeclared[builtins.KurtosisModuleName] = kurtosisModule // Add all Kurtosis helpers - for _, kurtosisHelper := range KurtosisHelpers(packageId, recursiveInterpretForModuleLoading, interpreter.moduleContentProvider, moduleGlobalCache) { + for _, kurtosisHelper := range KurtosisHelpers(packageId, recursiveInterpretForModuleLoading, interpreter.moduleContentProvider, moduleGlobalCache, packageReplaceOptions) { predeclared[kurtosisHelper.Name()] = kurtosisHelper } diff --git a/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go b/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go index 042416359c..9509ec817a 100644 --- a/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_interpreter_idempotent_test.go @@ -30,6 +30,8 @@ const ( noInputParams = "{}" ) +var noPackageReplaceOptions = map[string]string{} + type StartosisInterpreterIdempotentTestSuite struct { suite.Suite packageContentProvider *mock_package_content_provider.MockPackageContentProvider @@ -89,6 +91,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_I context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, noInputParams, @@ -102,6 +105,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_I _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, @@ -142,6 +146,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_A context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, initialScript, noInputParams, @@ -160,6 +165,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_A _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, updatedScript, @@ -201,6 +207,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_D context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, initialScript, noInputParams, @@ -217,6 +224,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_D _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, updatedScript, @@ -252,6 +260,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_I context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, initialScript, noInputParams, @@ -270,6 +279,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_I _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, updatedScript, @@ -311,6 +321,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_A context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, initialScript, noInputParams, @@ -330,6 +341,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_A _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, updatedScript, @@ -380,6 +392,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_U context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, + noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, initialScript, noInputParams, @@ -404,6 +417,7 @@ func (suite *StartosisInterpreterIdempotentTestSuite) TestInterpretAndOptimize_U _, instructionsPlan, interpretationError := suite.interpreter.InterpretAndOptimizePlan( context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, + noPackageReplaceOptions, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, updatedScript, diff --git a/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go b/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go index 68f5acc704..5963725fe6 100644 --- a/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_interpreter_test.go @@ -100,7 +100,7 @@ def run(plan): plan.print("` + testString + `") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) // Only the print statement @@ -121,7 +121,7 @@ def deploy_contract(plan,service_name,contract_name,init_message,args): mainFunctionName := "deploy_contract" inputArgs := `{"service_name": "my-service", "contract_name": "my-contract", "init_message": "Init message", "args": {"arg1": "arg1-value", "arg2": "arg2-value"}}` - result, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, inputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + result, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, inputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 3, instructionsPlan.Size()) // The three print functions require.NotNil(suite.T(), result) @@ -142,7 +142,7 @@ def my_func(my_arg1, my_arg2, args): mainFunctionName := "my_func" inputArgs := `{"my_arg1": "foo", "my_arg2": "bar", "args": {"arg1": "arg1-value", "arg2": "arg2-value"}}` - result, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, inputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + result, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, mainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, inputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 0, instructionsPlan.Size()) // There are no instructions to execute require.NotNil(suite.T(), result) @@ -159,7 +159,7 @@ def run(plan): plan.print(my_dict) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 2, instructionsPlan.Size()) @@ -177,7 +177,7 @@ def run(plan): unknownInstruction() ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCustomMsg( []startosis_errors.CallFrame{ @@ -198,7 +198,7 @@ unknownVariable unknownInstruction2() ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCustomMsg( []startosis_errors.CallFrame{ @@ -220,7 +220,7 @@ def run(): load("otherScript.start") # fails b/c load takes in at least 2 args ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorFromStacktrace( []startosis_errors.CallFrame{ @@ -252,7 +252,7 @@ def run(plan): plan.print("The grpc transport protocol is " + datastore_service.ports["grpc"].transport_protocol) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, fmt.Sprintf(script, testServiceName), startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, fmt.Sprintf(script, testServiceName), startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 5, instructionsPlan.Size()) @@ -287,7 +287,7 @@ def run(plan): plan.print("The transport protocol is " + datastore_service.ports["grpc"].transport_protocol) plan.print("The application protocol is " + datastore_service.ports["grpc"].application_protocol) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, fmt.Sprintf(script, testServiceName), startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, fmt.Sprintf(script, testServiceName), startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 6, instructionsPlan.Size()) @@ -317,7 +317,7 @@ def run(plan): plan.add_service(name = service_name, config = config) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCauseAndCustomMsg( errors.New("ServiceConfig: missing argument for image"), @@ -348,7 +348,7 @@ def run(plan): plan.add_service(name = service_name, config = config) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCauseAndCustomMsg( startosis_errors.NewInterpretationError(`The following argument(s) could not be parsed or did not pass validation: {"transport_protocol":"Invalid argument value for 'transport_protocol': 'TCPK'. Valid values are TCP, SCTP, UDP"}`), []startosis_errors.CallFrame{ @@ -378,7 +378,7 @@ def run(plan): plan.add_service(name = service_name, config = config) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCauseAndCustomMsg( startosis_errors.NewInterpretationError(`The following argument(s) could not be parsed or did not pass validation: {"number":"Value for 'number' was expected to be an integer between 1 and 65535, but it was 'starlark.String'"}`), []startosis_errors.CallFrame{ @@ -418,7 +418,7 @@ def run(plan): plan.print("Done!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 8, instructionsPlan.Size()) @@ -446,7 +446,7 @@ load("` + barModulePath + `", "a") def run(plan): plan.print("Hello " + a) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCustomMsg( []startosis_errors.CallFrame{ *startosis_errors.NewCallFrame("", startosis_errors.NewScriptPosition(startosis_constants.PackageIdPlaceholderForStandaloneScript, 2, 1)), @@ -469,7 +469,7 @@ my_module = import_module("` + barModulePath + `") def run(plan): plan.print("Hello " + my_module.a) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) // Only the print statement @@ -493,7 +493,7 @@ def run(plan): plan.print(module_doo.b) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) @@ -517,7 +517,7 @@ def run(plan): plan.print(module_doo.b) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) expectedError := startosis_errors.NewInterpretationErrorWithCustomMsg( []startosis_errors.CallFrame{ *startosis_errors.NewCallFrame("", startosis_errors.NewScriptPosition(moduleBarLoadsModuleDoo, 1, 27)), @@ -538,7 +538,7 @@ def run(plan): plan.print(my_module.b) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) errorMsg := `Evaluation error: An error occurred while loading the module '` + nonExistentModule + `' Caused by: Package '` + nonExistentModule + `' not found` @@ -561,7 +561,7 @@ def run(plan): ` // assert that first load fails - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) require.Nil(suite.T(), instructionsPlan) @@ -570,7 +570,7 @@ def run(plan): expectedOutput := `Hello World! ` // assert that second load succeeds - _, instructionsPlan, interpretationError = suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError = suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) validateScriptOutputFromPrintInstructions(suite.T(), instructionsPlan, expectedOutput) @@ -597,7 +597,7 @@ def run(plan): plan.add_service(name = module_bar.service_name, config = module_bar.config) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 3, instructionsPlan.Size()) @@ -641,7 +641,7 @@ def run(plan): plan.print("Done!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 8, instructionsPlan.Size()) @@ -670,7 +670,7 @@ def run(plan): plan.print("World!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) @@ -708,7 +708,7 @@ Adding service example-datastore-server Starting Startosis script! ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, scriptA, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, scriptA, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 4, instructionsPlan.Size()) assertInstructionTypeAndPosition(suite.T(), instructionsPlan, 2, add_service.AddServiceBuiltinName, moduleBar, 12, 18) @@ -733,7 +733,7 @@ def run(plan): Adding service example-datastore-server ` - _, instructionsPlan, interpretationError = suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, scriptB, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError = suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, scriptB, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 3, instructionsPlan.Size()) assertInstructionTypeAndPosition(suite.T(), instructionsPlan, 2, add_service.AddServiceBuiltinName, startosis_constants.PackageIdPlaceholderForStandaloneScript, 14, 18) @@ -753,7 +753,7 @@ def run(plan): plan.print(file_contents) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 2, instructionsPlan.Size()) @@ -787,7 +787,7 @@ def run(plan): plan.print(artifact_name) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 3, instructionsPlan.Size()) @@ -826,7 +826,7 @@ def run(plan): plan.print(uuid) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 4, instructionsPlan.Size()) @@ -848,7 +848,7 @@ def run(plan): plan.print("The service example-datastore-server has been removed") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 3, instructionsPlan.Size()) @@ -866,7 +866,7 @@ func (suite *StartosisInterpreterTestSuite) TestStartosisInterpreter_NoPanicIfUp def run(plan): plan.upload_files("` + filePath + `") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) require.Nil(suite.T(), instructionsPlan) } @@ -877,7 +877,7 @@ def run(plan): plan.print("Hello World!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) @@ -892,7 +892,7 @@ def run(plan): plan.print("Hello World!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"number": 4}`, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"number": 4}`, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) require.Nil(suite.T(), instructionsPlan) } @@ -903,7 +903,7 @@ def run(plan, args): plan.print("My favorite number is {0}".format(args["number"])) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"number": 4}`, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"number": 4}`, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) @@ -921,7 +921,7 @@ def run(plan, args): plan.print("Sorry no args!") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) @@ -936,7 +936,7 @@ def run(plan, args, invalid_arg): plan.print("this wouldn't interpret so the text here doesnt matter") ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) expectedError := "Evaluation error: function run missing 2 arguments (args, invalid_arg)" require.Contains(suite.T(), interpretationError.GetErrorMessage(), expectedError) @@ -950,7 +950,7 @@ def run(plan, a, b): ` missingArgumentCount := 1 missingArgument := "b" - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"a": "x"}`, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"a": "x"}`, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) expectedError := fmt.Sprintf("Evaluation error: function run missing %d argument (%v)", missingArgumentCount, missingArgument) @@ -963,7 +963,7 @@ func (suite *StartosisInterpreterTestSuite) TestStartosisInterpreter_RunWithUnpa def run(plan, a, b=1): plan.print("My favorite number is {0}, but my favorite letter is {1}".format(b, a)) ` - _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"a": "x"}`, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, instructionsPlan, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, `{"a": "x"}`, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) require.Equal(suite.T(), 1, instructionsPlan.Size()) expectedOutput := "My favorite number is 1, but my favorite letter is x\n" @@ -976,7 +976,7 @@ def run(plan): print("this doesnt matter") ` - _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) require.Equal(suite.T(), fmt.Sprintf("Evaluation error: %v\n\tat [3:7]: run\n\tat [0:0]: print", print_builtin.UsePlanFromKurtosisInstructionError), interpretationError.GetErrorMessage()) } @@ -987,7 +987,7 @@ def run(plan): time.now() ` - _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.NotNil(suite.T(), interpretationError) require.Equal(suite.T(), fmt.Sprintf("Evaluation error: %v\n\tat [3:10]: run\n\tat [0:0]: now", time_now_builtin.UseRunPythonInsteadOfTimeNowError), interpretationError.GetErrorMessage()) } @@ -998,7 +998,7 @@ def run(plan): time.parse_duration("5s") ` - _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) + _, _, interpretationError := suite.interpreter.Interpret(context.Background(), startosis_constants.PackageIdPlaceholderForStandaloneScript, useDefaultMainFunctionName, noPackageReplaceOptions, startosis_constants.PlaceHolderMainFileForPlaceStandAloneScript, script, startosis_constants.EmptyInputArgs, emptyEnclaveComponents, emptyInstructionsPlanMask) require.Nil(suite.T(), interpretationError) } diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider.go index 6ebb2420ac..a0c4dccbfe 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider.go @@ -36,6 +36,8 @@ const ( packageDocLink = "https://docs.kurtosis.com/concepts-reference/packages" osPathSeparatorString = string(os.PathSeparator) + + onlyOneReplace = 1 ) type GitPackageContentProvider struct { @@ -50,31 +52,36 @@ func NewGitPackageContentProvider(moduleDir string, tmpDir string) *GitPackageCo } } -func (provider *GitPackageContentProvider) ClonePackage(packageId string) (string, string, *startosis_errors.InterpretationError) { +func (provider *GitPackageContentProvider) ClonePackage(packageId string) (string, *startosis_errors.InterpretationError) { parsedURL, interpretationError := parseGitURL(packageId) if interpretationError != nil { - return "", "", interpretationError + return "", interpretationError } interpretationError = provider.atomicClone(parsedURL) if interpretationError != nil { - return "", "", interpretationError + return "", interpretationError } relPackagePathToPackagesDir := getPathToPackageRoot(parsedURL) packageAbsolutePathOnDisk := path.Join(provider.packagesDir, relPackagePathToPackagesDir) + return packageAbsolutePathOnDisk, nil +} + +func (provider *GitPackageContentProvider) GetKurtosisYaml(packageAbsolutePathOnDisk string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError) { pathToKurtosisYaml := path.Join(packageAbsolutePathOnDisk, startosis_constants.KurtosisYamlName) if _, err := os.Stat(pathToKurtosisYaml); err != nil { - return "", "", startosis_errors.WrapWithInterpretationError(err, "Couldn't find a '%v' in the root of the package: '%v'. Packages are expected to have a '%v' at root; for more information have a look at %v", - startosis_constants.KurtosisYamlName, packageId, startosis_constants.KurtosisYamlName, packageDocLink) + return nil, startosis_errors.WrapWithInterpretationError(err, "Couldn't find a '%v' in the root of the package: '%v'. Packages are expected to have a '%v' at root; for more information have a look at %v", + startosis_constants.KurtosisYamlName, packageAbsolutePathOnDisk, startosis_constants.KurtosisYamlName, packageDocLink) } kurtosisYaml, interpretationError := validateAndGetKurtosisYaml(pathToKurtosisYaml, provider.packagesDir) if interpretationError != nil { - return "", "", interpretationError + return nil, interpretationError } - return packageAbsolutePathOnDisk, kurtosisYaml.PackageName, nil + + return kurtosisYaml, nil } func (provider *GitPackageContentProvider) GetOnDiskAbsoluteFilePath(fileInsidePackageUrl string) (string, *startosis_errors.InterpretationError) { @@ -106,7 +113,7 @@ func (provider *GitPackageContentProvider) GetOnDiskAbsoluteFilePath(fileInsideP return "", interpretationError } - // check whether kurtosis yaml exists in th path + // check whether kurtosis yaml exists in the path maybeKurtosisYamlPath, err := getKurtosisYamlPathForFileUrl(pathToFileOnDisk, provider.packagesDir) if err != nil { return "", startosis_errors.WrapWithInterpretationError(err, "Error occurred while verifying whether '%v' belongs to a Kurtosis package.", fileInsidePackageUrl) @@ -193,19 +200,68 @@ func (provider *GitPackageContentProvider) StorePackageContents(packageId string return packageAbsolutePathOnDisk, nil } -func (provider *GitPackageContentProvider) GetAbsoluteLocatorForRelativeModuleLocator(parentModuleId string, maybeRelativeLocator string) (string, *startosis_errors.InterpretationError) { +func (provider *GitPackageContentProvider) GetAbsoluteLocatorForRelativeLocator( + parentModuleId string, + maybeRelativeLocator string, + packageReplaceOptions map[string]string, +) (string, *startosis_errors.InterpretationError) { + var absoluteLocator string + // maybe it's not a relative url in which case we return the url _, errorParsingUrl := parseGitURL(maybeRelativeLocator) if errorParsingUrl == nil { - return maybeRelativeLocator, nil + absoluteLocator = maybeRelativeLocator + } else { + parsedParentModuleId, errorParsingPackageId := parseGitURL(parentModuleId) + if errorParsingPackageId != nil { + return "", startosis_errors.NewInterpretationError("Parent package id '%v' isn't a valid locator; relative URLs don't work with standalone scripts", parentModuleId) + } + + absoluteLocator = parsedParentModuleId.getAbsoluteLocatorRelativeToThisURL(maybeRelativeLocator) } - parsedParentModuleId, errorParsingPackageId := parseGitURL(parentModuleId) - if errorParsingPackageId != nil { - return "", startosis_errors.NewInterpretationError("Parent package id '%v' isn't a valid locator; relative URLs don't work with standalone scripts", parentModuleId) + replacedAbsoluteLocator := replaceAbsoluteLocator(absoluteLocator, packageReplaceOptions) + + return replacedAbsoluteLocator, nil +} + +func replaceAbsoluteLocator(absoluteLocator string, packageReplaceOptions map[string]string) string { + if absoluteLocator == "" { + return absoluteLocator + } + + found, packageToBeReplaced, replaceWithPackage := findPackageReplace(absoluteLocator, packageReplaceOptions) + if found { + replacedAbsoluteLocator := strings.Replace(absoluteLocator, packageToBeReplaced, replaceWithPackage, onlyOneReplace) + logrus.Debugf("absoluteLocator '%s' replaced with '%s'", absoluteLocator, replacedAbsoluteLocator) + return replacedAbsoluteLocator + } + + return absoluteLocator +} + +func findPackageReplace(absoluteLocator string, packageReplaceOptions map[string]string) (bool, string, string) { + pathToAnalyze := absoluteLocator + for { + numberSlashes := strings.Count(pathToAnalyze, urlPathSeparator) + + // check for the minimal path e.g.: github.com/org/package + if numberSlashes < minimumSubPathsForValidGitURL { + break + } + lastIndex := strings.LastIndex(pathToAnalyze, urlPathSeparator) + + packageToBeReplaced := pathToAnalyze[:lastIndex] + replaceWithPackage, ok := packageReplaceOptions[packageToBeReplaced] + if ok { + logrus.Debugf("dependency replace found for '%s', package '%s' will be replaced with '%s'", absoluteLocator, packageToBeReplaced, replaceWithPackage) + return true, packageToBeReplaced, replaceWithPackage + } + + pathToAnalyze = packageToBeReplaced } - return parsedParentModuleId.getAbsoluteLocatorRelativeToThisURL(maybeRelativeLocator), nil + return false, "", "" } // atomicClone This first clones to a temporary directory and then moves it diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index 30680e3a89..98692710f5 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -13,10 +13,13 @@ import ( ) const ( - packagesDirRelPath = "startosis-packages" - packagesTmpDirRelPath = "tmp-startosis-packages" + packagesDirRelPath = "startosis-packages" + packagesTmpDirRelPath = "tmp-startosis-packages" + packageDescriptionForTest = "package description test" ) +var noPackageReplaceOptions = map[string]string{} + func TestGitPackageProvider_SucceedsForValidPackage(t *testing.T) { packageDir, err := os.MkdirTemp("", packagesDirRelPath) require.Nil(t, err) @@ -176,7 +179,7 @@ func TestGetAbsolutePathOnDisk_WorksForPureDirectories(t *testing.T) { require.Equal(t, path.Join(packageDir, "kurtosis-tech", "datastore-army-package", "src/helpers.star"), pathOnDisk) } -func TestGetAbsoluteLocatorForRelativeModuleLocator_SucceedsForRelativeFile(t *testing.T) { +func TestGetAbsolutePathOnDisk_WorksForNonInMainBranchLocators(t *testing.T) { packageDir, err := os.MkdirTemp("", packagesDirRelPath) require.Nil(t, err) defer os.RemoveAll(packageDir) @@ -186,9 +189,19 @@ func TestGetAbsoluteLocatorForRelativeModuleLocator_SucceedsForRelativeFile(t *t provider := NewGitPackageContentProvider(packageDir, packageTmpDir) + absoluteFileLocator := "github.com/kurtosis-tech/sample-dependency-package@test-branch/main.star" + pathOnDisk, err := provider.GetOnDiskAbsoluteFilePath(absoluteFileLocator) + + require.Nil(t, err, "This test depends on your internet working and the kurtosis-tech/datastore-army-package existing") + require.Equal(t, path.Join(packageDir, "kurtosis-tech", "sample-dependency-package", "main.star"), pathOnDisk) +} + +func TestGetAbsoluteLocatorForRelativeModuleLocator_SucceedsForRelativeFile(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + parentModuleId := "github.com/kurtosis-tech/avalanche-package/src/builder.star" maybeRelativeLocator := "../static_files/config.json.tmpl" - absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeModuleLocator(parentModuleId, maybeRelativeLocator) + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, noPackageReplaceOptions) expectedAbsoluteLocator := "github.com/kurtosis-tech/avalanche-package/static_files/config.json.tmpl" require.Nil(t, err) @@ -196,13 +209,93 @@ func TestGetAbsoluteLocatorForRelativeModuleLocator_SucceedsForRelativeFile(t *t parentModuleId2 := "github.com/kurtosis-tech/avalanche-package/src/builder.star" maybeRelativeLocator2 := "/static_files/genesis.json" - absoluteLocator2, err2 := provider.GetAbsoluteLocatorForRelativeModuleLocator(parentModuleId2, maybeRelativeLocator2) + absoluteLocator2, err2 := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId2, maybeRelativeLocator2, noPackageReplaceOptions) expectedAbsoluteLocator2 := "github.com/kurtosis-tech/avalanche-package/static_files/genesis.json" require.Nil(t, err2) require.Equal(t, expectedAbsoluteLocator2, absoluteLocator2) } +func TestGetAbsoluteLocatorForRelativeModuleLocator_RegularReplaceSucceeds(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + + parentModuleId := "github.com/kurtosis-tech/sample-startosis-load/sample-package/main.star" + maybeRelativeLocator := "github.com/kurtosis-tech/sample-dependency-package/main.star" + packageReplaceOptions := map[string]string{ + "github.com/kurtosis-tech/sample-dependency-package": "github.com/kurtosis-tech/another-sample-dependency-package", + } + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, packageReplaceOptions) + + expectedAbsoluteLocator := "github.com/kurtosis-tech/another-sample-dependency-package/main.star" + require.Nil(t, err) + require.Equal(t, expectedAbsoluteLocator, absoluteLocator) + +} + +func TestGetAbsoluteLocatorForRelativeModuleLocator_RootPackageReplaceSucceeds(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + + parentModuleId := "github.com/kurtosis-tech/sample-startosis-load/sample-package/main.star" + maybeRelativeLocator := "github.com/kurtosis-tech/another-sample-dependency-package/main.star" + packageReplaceOptions := map[string]string{ + "github.com/kurtosis-tech/another-sample-dependency-package": "github.com/kurtosis-tech/root-package-replaced", + "github.com/kurtosis-tech/another-sample-dependency-package/subpackage": "github.com/kurtosis-tech/sub-package-replaced", + } + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, packageReplaceOptions) + + expectedAbsoluteLocator := "github.com/kurtosis-tech/root-package-replaced/main.star" + require.Nil(t, err) + require.Equal(t, expectedAbsoluteLocator, absoluteLocator) + +} + +func TestGetAbsoluteLocatorForRelativeModuleLocator_SubPackageReplaceSucceeds(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + + parentModuleId := "github.com/kurtosis-tech/sample-startosis-load/sample-package/main.star" + maybeRelativeLocator := "github.com/kurtosis-tech/another-sample-dependency-package/subpackage/main.star" + packageReplaceOptions := map[string]string{ + "github.com/kurtosis-tech/another-sample-dependency-package": "github.com/kurtosis-tech/root-package-replaced", + "github.com/kurtosis-tech/another-sample-dependency-package/subpackage": "github.com/kurtosis-tech/sub-package-replaced", + } + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, packageReplaceOptions) + + expectedAbsoluteLocator := "github.com/kurtosis-tech/sub-package-replaced/main.star" + require.Nil(t, err) + require.Equal(t, expectedAbsoluteLocator, absoluteLocator) + +} + +func TestGetAbsoluteLocatorForRelativeModuleLocator_ReplacePackageInternalModuleSucceeds(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + + parentModuleId := "github.com/kurtosis-tech/sample-startosis-load/sample-package/main.star" + maybeRelativeLocator := "github.com/kurtosis-tech/another-sample-dependency-package/folder/module.star" + packageReplaceOptions := map[string]string{ + "github.com/kurtosis-tech/another-sample-dependency-package": "github.com/kurtosis-tech/root-package-replaced", + } + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, packageReplaceOptions) + + expectedAbsoluteLocator := "github.com/kurtosis-tech/root-package-replaced/folder/module.star" + require.Nil(t, err) + require.Equal(t, expectedAbsoluteLocator, absoluteLocator) +} + +func TestGetAbsoluteLocatorForRelativeModuleLocator_NoMainBranchReplaceSucceeds(t *testing.T) { + provider := NewGitPackageContentProvider("", "") + + parentModuleId := "github.com/kurtosis-tech/sample-startosis-load/sample-package/main.star" + maybeRelativeLocator := "github.com/kurtosis-tech/sample-dependency-package/main.star" + packageReplaceOptions := map[string]string{ + "github.com/kurtosis-tech/sample-dependency-package": "github.com/kurtosis-tech/sample-dependency-package@no-main-branch", + } + absoluteLocator, err := provider.GetAbsoluteLocatorForRelativeLocator(parentModuleId, maybeRelativeLocator, packageReplaceOptions) + + expectedAbsoluteLocator := "github.com/kurtosis-tech/sample-dependency-package@no-main-branch/main.star" + require.Nil(t, err) + require.Equal(t, expectedAbsoluteLocator, absoluteLocator) +} + func Test_getPathToPackageRoot(t *testing.T) { githubUrlWithKurtosisPackageInSubfolder := "github.com/sample/sample-package/folder/subpackage" parsedGitUrl, err := parseGitURL(githubUrlWithKurtosisPackageInSubfolder) @@ -329,9 +422,7 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { { name: "failure - mismatch package name and path (incorrect package name)", args: args{ - kurtosisYaml: &yaml_parser.KurtosisYaml{ - PackageName: "github.com/author/repo/packageIncorrect", - }, + kurtosisYaml: createKurtosisYml("github.com/author/repo/packageIncorrect"), absPathToPackageWithKurtosisYml: "/root/folder/author/repo/package/kurtosis.yml", packagesDir: "/root/folder", }, @@ -340,9 +431,7 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { { name: "failure - mismatch package name and path (different location)", args: args{ - kurtosisYaml: &yaml_parser.KurtosisYaml{ - PackageName: "github.com/author/repo", - }, + kurtosisYaml: createKurtosisYml("github.com/author/repo"), absPathToPackageWithKurtosisYml: "/root/folder/author/repo/subfolder/kurtosis.yml", packagesDir: "/root/folder", }, @@ -351,9 +440,7 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { { name: "failure - contains a trailing '/'", args: args{ - kurtosisYaml: &yaml_parser.KurtosisYaml{ - PackageName: "github.com/author/repo/subfolder/", - }, + kurtosisYaml: createKurtosisYml("github.com/author/repo/subfolder/"), absPathToPackageWithKurtosisYml: "/root/folder/author/repo/subfolder/kurtosis.yml", packagesDir: "/root/folder", }, @@ -362,9 +449,7 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { { name: "success - kurtosis.yml found in repo folder", args: args{ - kurtosisYaml: &yaml_parser.KurtosisYaml{ - PackageName: "github.com/author/repo", - }, + kurtosisYaml: createKurtosisYml("github.com/author/repo"), absPathToPackageWithKurtosisYml: "/root/folder/author/repo/kurtosis.yml", packagesDir: "/root/folder", }, @@ -373,9 +458,7 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { { name: "success - kurtosis.yml found in sub folder folder", args: args{ - kurtosisYaml: &yaml_parser.KurtosisYaml{ - PackageName: "github.com/author/repo/subfolder", - }, + kurtosisYaml: createKurtosisYml("github.com/author/repo/subfolder"), absPathToPackageWithKurtosisYml: "/root/folder/author/repo/subfolder/kurtosis.yml", packagesDir: "/root/folder", }, @@ -393,3 +476,11 @@ func Test_validatePackageNameMatchesKurtosisYamlLocation(t *testing.T) { }) } } + +func createKurtosisYml(packageName string) *yaml_parser.KurtosisYaml { + return &yaml_parser.KurtosisYaml{ + PackageName: packageName, + PackageDescription: packageDescriptionForTest, + PackageReplaceOptions: noPackageReplaceOptions, + } +} diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/parsed_git_url.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/parsed_git_url.go index 847005fdaf..32136cb138 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/parsed_git_url.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/parsed_git_url.go @@ -125,9 +125,21 @@ func cleanPathAndSplit(urlPath string) []string { return sliceWithoutEmptyStrings } -// parseOutTagBranchOrCommit splits the string around "@" +// parseOutTagBranchOrCommit splits the string around "@" and then split the after string around "/" func parseOutTagBranchOrCommit(input string) (string, string) { cleanInput := path.Clean(input) - pathWithoutVersion, maybeTagBranchOrCommit, _ := strings.Cut(cleanInput, tagBranchOrCommitDelimiter) + pathWithoutVersion, maybeTagBranchOrCommitWithFile, _ := strings.Cut(cleanInput, tagBranchOrCommitDelimiter) + + // input can have been set with version in two diff ways + // 1- github.com/kurtosis-tech/sample-dependency-package/main.star@branch-or-version (when is called from cli run command) + // 2- github.com/kurtosis-tech/sample-dependency-package@branch-or-version/main.star (when is declared in the replace section of the kurtosis.yml file) + // we check if there is a file in maybeTagBranchOrCommitWithFile and then add it to pathWithoutVersion + maybeTagBranchOrCommit, maybeFileNameAndExtension, _ := strings.Cut(maybeTagBranchOrCommitWithFile, urlPathSeparator) + + if maybeFileNameAndExtension != "" { + // we assume pathWithoutVersion does not contain a file inside yet + pathWithoutVersion = path.Join(pathWithoutVersion, maybeFileNameAndExtension) + } + return pathWithoutVersion, maybeTagBranchOrCommit } diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider.go b/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider.go index 922b4c2473..94cad82006 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider.go @@ -6,6 +6,7 @@ import ( io "io" startosis_errors "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors" + yaml_parser "github.com/kurtosis-tech/kurtosis/core/server/commons/yaml_parser" mock "github.com/stretchr/testify/mock" ) @@ -23,13 +24,12 @@ func (_m *MockPackageContentProvider) EXPECT() *MockPackageContentProvider_Expec } // ClonePackage provides a mock function with given fields: packageId -func (_m *MockPackageContentProvider) ClonePackage(packageId string) (string, string, *startosis_errors.InterpretationError) { +func (_m *MockPackageContentProvider) ClonePackage(packageId string) (string, *startosis_errors.InterpretationError) { ret := _m.Called(packageId) var r0 string - var r1 string - var r2 *startosis_errors.InterpretationError - if rf, ok := ret.Get(0).(func(string) (string, string, *startosis_errors.InterpretationError)); ok { + var r1 *startosis_errors.InterpretationError + if rf, ok := ret.Get(0).(func(string) (string, *startosis_errors.InterpretationError)); ok { return rf(packageId) } if rf, ok := ret.Get(0).(func(string) string); ok { @@ -38,21 +38,15 @@ func (_m *MockPackageContentProvider) ClonePackage(packageId string) (string, st r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(string) string); ok { + if rf, ok := ret.Get(1).(func(string) *startosis_errors.InterpretationError); ok { r1 = rf(packageId) } else { - r1 = ret.Get(1).(string) - } - - if rf, ok := ret.Get(2).(func(string) *startosis_errors.InterpretationError); ok { - r2 = rf(packageId) - } else { - if ret.Get(2) != nil { - r2 = ret.Get(2).(*startosis_errors.InterpretationError) + if ret.Get(1) != nil { + r1 = ret.Get(1).(*startosis_errors.InterpretationError) } } - return r0, r1, r2 + return r0, r1 } // MockPackageContentProvider_ClonePackage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ClonePackage' @@ -73,33 +67,33 @@ func (_c *MockPackageContentProvider_ClonePackage_Call) Run(run func(packageId s return _c } -func (_c *MockPackageContentProvider_ClonePackage_Call) Return(_a0 string, _a1 string, _a2 *startosis_errors.InterpretationError) *MockPackageContentProvider_ClonePackage_Call { - _c.Call.Return(_a0, _a1, _a2) +func (_c *MockPackageContentProvider_ClonePackage_Call) Return(_a0 string, _a1 *startosis_errors.InterpretationError) *MockPackageContentProvider_ClonePackage_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *MockPackageContentProvider_ClonePackage_Call) RunAndReturn(run func(string) (string, string, *startosis_errors.InterpretationError)) *MockPackageContentProvider_ClonePackage_Call { +func (_c *MockPackageContentProvider_ClonePackage_Call) RunAndReturn(run func(string) (string, *startosis_errors.InterpretationError)) *MockPackageContentProvider_ClonePackage_Call { _c.Call.Return(run) return _c } -// GetAbsoluteLocatorForRelativeModuleLocator provides a mock function with given fields: packageId, relativeOrAbsoluteModulePath -func (_m *MockPackageContentProvider) GetAbsoluteLocatorForRelativeModuleLocator(packageId string, relativeOrAbsoluteModulePath string) (string, *startosis_errors.InterpretationError) { - ret := _m.Called(packageId, relativeOrAbsoluteModulePath) +// GetAbsoluteLocatorForRelativeLocator provides a mock function with given fields: packageId, relativeOrAbsoluteLocator, packageReplaceOptions +func (_m *MockPackageContentProvider) GetAbsoluteLocatorForRelativeLocator(packageId string, relativeOrAbsoluteLocator string, packageReplaceOptions map[string]string) (string, *startosis_errors.InterpretationError) { + ret := _m.Called(packageId, relativeOrAbsoluteLocator, packageReplaceOptions) var r0 string var r1 *startosis_errors.InterpretationError - if rf, ok := ret.Get(0).(func(string, string) (string, *startosis_errors.InterpretationError)); ok { - return rf(packageId, relativeOrAbsoluteModulePath) + if rf, ok := ret.Get(0).(func(string, string, map[string]string) (string, *startosis_errors.InterpretationError)); ok { + return rf(packageId, relativeOrAbsoluteLocator, packageReplaceOptions) } - if rf, ok := ret.Get(0).(func(string, string) string); ok { - r0 = rf(packageId, relativeOrAbsoluteModulePath) + if rf, ok := ret.Get(0).(func(string, string, map[string]string) string); ok { + r0 = rf(packageId, relativeOrAbsoluteLocator, packageReplaceOptions) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(string, string) *startosis_errors.InterpretationError); ok { - r1 = rf(packageId, relativeOrAbsoluteModulePath) + if rf, ok := ret.Get(1).(func(string, string, map[string]string) *startosis_errors.InterpretationError); ok { + r1 = rf(packageId, relativeOrAbsoluteLocator, packageReplaceOptions) } else { if ret.Get(1) != nil { r1 = ret.Get(1).(*startosis_errors.InterpretationError) @@ -109,31 +103,88 @@ func (_m *MockPackageContentProvider) GetAbsoluteLocatorForRelativeModuleLocator return r0, r1 } -// MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAbsoluteLocatorForRelativeModuleLocator' -type MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call struct { +// MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAbsoluteLocatorForRelativeLocator' +type MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call struct { *mock.Call } -// GetAbsoluteLocatorForRelativeModuleLocator is a helper method to define mock.On call +// GetAbsoluteLocatorForRelativeLocator is a helper method to define mock.On call // - packageId string -// - relativeOrAbsoluteModulePath string -func (_e *MockPackageContentProvider_Expecter) GetAbsoluteLocatorForRelativeModuleLocator(packageId interface{}, relativeOrAbsoluteModulePath interface{}) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call { - return &MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call{Call: _e.mock.On("GetAbsoluteLocatorForRelativeModuleLocator", packageId, relativeOrAbsoluteModulePath)} +// - relativeOrAbsoluteLocator string +// - packageReplaceOptions map[string]string +func (_e *MockPackageContentProvider_Expecter) GetAbsoluteLocatorForRelativeLocator(packageId interface{}, relativeOrAbsoluteLocator interface{}, packageReplaceOptions interface{}) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call { + return &MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call{Call: _e.mock.On("GetAbsoluteLocatorForRelativeLocator", packageId, relativeOrAbsoluteLocator, packageReplaceOptions)} +} + +func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call) Run(run func(packageId string, relativeOrAbsoluteLocator string, packageReplaceOptions map[string]string)) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string), args[2].(map[string]string)) + }) + return _c +} + +func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call) Return(_a0 string, _a1 *startosis_errors.InterpretationError) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call) RunAndReturn(run func(string, string, map[string]string) (string, *startosis_errors.InterpretationError)) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeLocator_Call { + _c.Call.Return(run) + return _c } -func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call) Run(run func(packageId string, relativeOrAbsoluteModulePath string)) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call { +// GetKurtosisYaml provides a mock function with given fields: packageAbsolutePathOnDisk +func (_m *MockPackageContentProvider) GetKurtosisYaml(packageAbsolutePathOnDisk string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError) { + ret := _m.Called(packageAbsolutePathOnDisk) + + var r0 *yaml_parser.KurtosisYaml + var r1 *startosis_errors.InterpretationError + if rf, ok := ret.Get(0).(func(string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError)); ok { + return rf(packageAbsolutePathOnDisk) + } + if rf, ok := ret.Get(0).(func(string) *yaml_parser.KurtosisYaml); ok { + r0 = rf(packageAbsolutePathOnDisk) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*yaml_parser.KurtosisYaml) + } + } + + if rf, ok := ret.Get(1).(func(string) *startosis_errors.InterpretationError); ok { + r1 = rf(packageAbsolutePathOnDisk) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*startosis_errors.InterpretationError) + } + } + + return r0, r1 +} + +// MockPackageContentProvider_GetKurtosisYaml_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKurtosisYaml' +type MockPackageContentProvider_GetKurtosisYaml_Call struct { + *mock.Call +} + +// GetKurtosisYaml is a helper method to define mock.On call +// - packageAbsolutePathOnDisk string +func (_e *MockPackageContentProvider_Expecter) GetKurtosisYaml(packageAbsolutePathOnDisk interface{}) *MockPackageContentProvider_GetKurtosisYaml_Call { + return &MockPackageContentProvider_GetKurtosisYaml_Call{Call: _e.mock.On("GetKurtosisYaml", packageAbsolutePathOnDisk)} +} + +func (_c *MockPackageContentProvider_GetKurtosisYaml_Call) Run(run func(packageAbsolutePathOnDisk string)) *MockPackageContentProvider_GetKurtosisYaml_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(string)) + run(args[0].(string)) }) return _c } -func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call) Return(_a0 string, _a1 *startosis_errors.InterpretationError) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call { +func (_c *MockPackageContentProvider_GetKurtosisYaml_Call) Return(_a0 *yaml_parser.KurtosisYaml, _a1 *startosis_errors.InterpretationError) *MockPackageContentProvider_GetKurtosisYaml_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call) RunAndReturn(run func(string, string) (string, *startosis_errors.InterpretationError)) *MockPackageContentProvider_GetAbsoluteLocatorForRelativeModuleLocator_Call { +func (_c *MockPackageContentProvider_GetKurtosisYaml_Call) RunAndReturn(run func(string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError)) *MockPackageContentProvider_GetKurtosisYaml_Call { _c.Call.Return(run) return _c } diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider/mock_package_content_provider.go b/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider/mock_package_content_provider.go index a4320675a9..433408bc03 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider/mock_package_content_provider.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/mock_package_content_provider/mock_package_content_provider.go @@ -3,6 +3,7 @@ package mock_package_content_provider import ( "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/commons/yaml_parser" "github.com/kurtosis-tech/stacktrace" "io" "os" @@ -42,7 +43,7 @@ func (provider *MockPackageContentProvider) GetOnDiskAbsoluteFilePath(packageId return absFilePath, nil } -func (provider *MockPackageContentProvider) ClonePackage(_ string) (string, string, *startosis_errors.InterpretationError) { +func (provider *MockPackageContentProvider) ClonePackage(_ string) (string, *startosis_errors.InterpretationError) { panic(unimplementedMessage) } @@ -55,6 +56,10 @@ func (provider *MockPackageContentProvider) StorePackageContents(_ string, _ io. panic(unimplementedMessage) } +func (provider *MockPackageContentProvider) GetKurtosisYaml(packageAbsolutePathOnDisk string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError) { + panic(unimplementedMessage) +} + func (provider *MockPackageContentProvider) GetModuleContents(fileInsidePackageUrl string) (string, *startosis_errors.InterpretationError) { absFilePath, found := provider.starlarkPackages[fileInsidePackageUrl] if !found { @@ -67,7 +72,7 @@ func (provider *MockPackageContentProvider) GetModuleContents(fileInsidePackageU return string(fileContent), nil } -func (provider *MockPackageContentProvider) GetAbsoluteLocatorForRelativeModuleLocator(_ string, relativeOrAbsoluteModulePath string) (string, *startosis_errors.InterpretationError) { +func (provider *MockPackageContentProvider) GetAbsoluteLocatorForRelativeLocator(_ string, relativeOrAbsoluteModulePath string, packageReplaceOptions map[string]string) (string, *startosis_errors.InterpretationError) { if strings.HasPrefix(relativeOrAbsoluteModulePath, startosis_constants.GithubDomainPrefix) { return relativeOrAbsoluteModulePath, nil } diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/package_content_provider.go b/core/server/api_container/server/startosis_engine/startosis_packages/package_content_provider.go index fd3f126655..9780003cf5 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/package_content_provider.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/package_content_provider.go @@ -2,6 +2,7 @@ package startosis_packages import ( "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_errors" + "github.com/kurtosis-tech/kurtosis/core/server/commons/yaml_parser" "io" ) @@ -25,9 +26,13 @@ type PackageContentProvider interface { // StorePackageContents writes on disk the content of the package passed as params StorePackageContents(packageId string, packageContent io.Reader, overwriteExisting bool) (string, *startosis_errors.InterpretationError) - // ClonePackage clones the package with the given id and returns the absolute path on disk and the package name from Kurtosis yaml file - ClonePackage(packageId string) (string, string, *startosis_errors.InterpretationError) + // ClonePackage clones the package with the given id and returns the absolute path on disk + ClonePackage(packageId string) (string, *startosis_errors.InterpretationError) - // GetAbsoluteLocatorForRelativeModuleLocator returns the absolute package path for a relative module path - GetAbsoluteLocatorForRelativeModuleLocator(packageId string, relativeOrAbsoluteModulePath string) (string, *startosis_errors.InterpretationError) + // GetAbsoluteLocatorForRelativeModuleLocator returns the absolute package path for a relative module path and replace the package path if + // there is a valid option in the noPackageReplaceOptions map + GetAbsoluteLocatorForRelativeLocator(packageId string, relativeOrAbsoluteLocator string, packageReplaceOptions map[string]string) (string, *startosis_errors.InterpretationError) + + // GetKurtosisYaml returns the package kurtosis.yml file content + GetKurtosisYaml(packageAbsolutePathOnDisk string) (*yaml_parser.KurtosisYaml, *startosis_errors.InterpretationError) } diff --git a/core/server/api_container/server/startosis_engine/startosis_runner.go b/core/server/api_container/server/startosis_engine/startosis_runner.go index 272a374eed..7e0a0901fe 100644 --- a/core/server/api_container/server/startosis_engine/startosis_runner.go +++ b/core/server/api_container/server/startosis_engine/startosis_runner.go @@ -48,6 +48,7 @@ func (runner *StartosisRunner) Run( dryRun bool, parallelism int, packageId string, + packageReplaceOptions map[string]string, mainFunctionName string, relativePathToMainFile string, serializedStartosis string, @@ -101,6 +102,7 @@ func (runner *StartosisRunner) Run( ctx, packageId, mainFunctionName, + packageReplaceOptions, relativePathToMainFile, serializedStartosis, serializedParams, @@ -111,6 +113,7 @@ func (runner *StartosisRunner) Run( serializedScriptOutput, instructionsPlan, interpretationError = runner.startosisInterpreter.InterpretAndOptimizePlan( ctx, packageId, + packageReplaceOptions, mainFunctionName, relativePathToMainFile, serializedStartosis, diff --git a/core/server/commons/yaml_parser/kurtosis_yaml.go b/core/server/commons/yaml_parser/kurtosis_yaml.go index adf48213eb..915832be58 100644 --- a/core/server/commons/yaml_parser/kurtosis_yaml.go +++ b/core/server/commons/yaml_parser/kurtosis_yaml.go @@ -3,13 +3,18 @@ package yaml_parser import ( "github.com/go-yaml/yaml" "github.com/kurtosis-tech/stacktrace" + "github.com/sirupsen/logrus" "os" ) var noPackageNameFound = "" +var naPackageDescriptionFound = "" +var noPackageReplaceOptions = map[string]string{} type KurtosisYaml struct { - PackageName string `yaml:"name"` + PackageName string `yaml:"name"` + PackageDescription string `yaml:"description"` + PackageReplaceOptions map[string]string `yaml:"replace"` } func (parser *KurtosisYaml) GetPackageName() string { @@ -19,6 +24,20 @@ func (parser *KurtosisYaml) GetPackageName() string { return parser.PackageName } +func (parser *KurtosisYaml) GetPackageDescription() string { + if parser == nil { + return naPackageDescriptionFound + } + return parser.PackageDescription +} + +func (parser *KurtosisYaml) GetPackageReplaceOptions() map[string]string { + if parser == nil { + return noPackageReplaceOptions + } + return parser.PackageReplaceOptions +} + // TODO: this parsing logic is similar to what have we in the api, maybe we should move everything into one // common package. This method assumes that the kurtosis.yml exists in the path provided. func parseKurtosisYamlInternal(absPathToKurtosisYaml string, read func(filename string) ([]byte, error)) (*KurtosisYaml, error) { @@ -28,9 +47,10 @@ func parseKurtosisYamlInternal(absPathToKurtosisYaml string, read func(filename } var kurtosisYaml KurtosisYaml - if err = yaml.Unmarshal(kurtosisYamlContent, &kurtosisYaml); err != nil { + if err = yaml.UnmarshalStrict(kurtosisYamlContent, &kurtosisYaml); err != nil { return nil, stacktrace.Propagate(err, "Error occurred while analyzing the contents of '%v'", absPathToKurtosisYaml) } + logrus.Debugf("parsed kurtosis.yml '%+v'", kurtosisYaml) return &kurtosisYaml, nil } diff --git a/core/server/commons/yaml_parser/kurtosis_yaml_test.go b/core/server/commons/yaml_parser/kurtosis_yaml_test.go index ee7d9f86d6..f2a4243a11 100644 --- a/core/server/commons/yaml_parser/kurtosis_yaml_test.go +++ b/core/server/commons/yaml_parser/kurtosis_yaml_test.go @@ -8,14 +8,40 @@ import ( ) var ( - kurtosisYmlPath = "/root/kurtosis.yml" - sampleCorrectYaml = []byte(`name: github.com/test-author/test-repo`) - sampleInCorrectYaml = []byte(`incorrect_name_key: github.com/test/test`) + kurtosisYmlPath = "/root/kurtosis.yml" + sampleCorrectYamlOnlyNameField = []byte(` +name: github.com/test-author/test-repo +`) + sampleCompleteCorrectYaml = []byte(` +name: github.com/test-author/test-repo +description: | + Some words to describe the package. +replace: + github.com/kurtosis-tech/sample-dependency-package: github.com/kurtosis-tech/another-sample-dependency-package + github.com/kurtosis-tech/ethereum-package: github.com/my-forked/ethereum-package +`) + sampleInCorrectKeyYaml = []byte(`incorrect_name_key: github.com/test/test`) + sampleDuplicatedReplaceKeyYaml = []byte(` +name: github.com/test-author/test-repo +replace: + github.com/kurtosis-tech/sample-dependency-package: github.com/kurtosis-tech/another-sample-dependency-package + github.com/kurtosis-tech/sample-dependency-package: github.com/my-forked/ethereum-package +`) ) func Test_parseKurtosisYamlInternal_Success(t *testing.T) { mockRead := func(filename string) ([]byte, error) { - return sampleCorrectYaml, nil + return sampleCompleteCorrectYaml, nil + } + + actual, err := parseKurtosisYamlInternal(kurtosisYmlPath, mockRead) + require.Nil(t, err) + require.Equal(t, "github.com/test-author/test-repo", actual.GetPackageName()) +} + +func Test_parseKurtosisYamlInternal_OnlyNameSuccess(t *testing.T) { + mockRead := func(filename string) ([]byte, error) { + return sampleCorrectYamlOnlyNameField, nil } actual, err := parseKurtosisYamlInternal(kurtosisYmlPath, mockRead) @@ -33,12 +59,22 @@ func Test_parseKurtosisYamlInternal_FailureWhileReading(t *testing.T) { require.ErrorContains(t, err, fmt.Sprintf("Error occurred while reading the contents of '%v'", kurtosisYmlPath)) } -func Test_parseKurtosisYamlInternal_IncorrectYaml(t *testing.T) { +func Test_parseKurtosisYamlInternal_IncorrectKeyYaml(t *testing.T) { mockRead := func(filename string) ([]byte, error) { - return sampleInCorrectYaml, nil + return sampleInCorrectKeyYaml, nil } - actual, err := parseKurtosisYamlInternal(kurtosisYmlPath, mockRead) - require.Nil(t, err) - require.Equal(t, "", actual.GetPackageName()) + _, err := parseKurtosisYamlInternal(kurtosisYmlPath, mockRead) + require.Error(t, err) + require.Contains(t, err.Error(), "incorrect_name_key not found") +} + +func Test_parseKurtosisYamlInternal_DuplicatedReplaceKeyYaml(t *testing.T) { + mockRead := func(filename string) ([]byte, error) { + return sampleDuplicatedReplaceKeyYaml, nil + } + + _, err := parseKurtosisYamlInternal(kurtosisYmlPath, mockRead) + require.Error(t, err) + require.Contains(t, err.Error(), "key \"github.com/kurtosis-tech/sample-dependency-package\" already set in map") } diff --git a/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_no_main_branch_replace_test.go b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_no_main_branch_replace_test.go new file mode 100644 index 0000000000..d2bb6a19e7 --- /dev/null +++ b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_no_main_branch_replace_test.go @@ -0,0 +1,24 @@ +package startosis_replace_test + +import ( + "context" + "github.com/stretchr/testify/require" +) + +const ( + packageWithNoMainBranchReplaceRelPath = "../../../starlark/packages-with-replace/replace-with-no-main-branch" + packageWithNoMainBranchReplaceParams = `{ "message_origin" : "branch" }` +) + +func (suite *StartosisReplaceTestSuite) TestStartosisNoMainBranchReplace() { + ctx := context.Background() + runResult, _ := suite.RunPackageWithParams(ctx, packageWithNoMainBranchReplaceRelPath, packageWithNoMainBranchReplaceParams) + + t := suite.T() + require.Nil(t, runResult.InterpretationError) + require.Empty(t, runResult.ValidationErrors) + require.Nil(t, runResult.ExecutionError) + expectedResult := "Replace with no main branch package loaded.\nVerification succeeded. Value is '\"dependency-loaded-from-test-branch\"'.\n" + require.Equal(t, expectedResult, string(runResult.RunOutput)) + +} diff --git a/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_regular_replace_test.go b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_regular_replace_test.go new file mode 100644 index 0000000000..942d5f3877 --- /dev/null +++ b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_regular_replace_test.go @@ -0,0 +1,24 @@ +package startosis_replace_test + +import ( + "context" + "github.com/stretchr/testify/require" +) + +const ( + packageWithRegularReplaceRelPath = "../../../starlark/packages-with-replace/regular-replace" + packageWithRegularReplaceParams = `{ "message_origin" : "another-main" }` +) + +func (suite *StartosisReplaceTestSuite) TestStartosisRegularReplace() { + ctx := context.Background() + runResult, _ := suite.RunPackageWithParams(ctx, packageWithRegularReplaceRelPath, packageWithRegularReplaceParams) + + t := suite.T() + require.Nil(t, runResult.InterpretationError) + require.Empty(t, runResult.ValidationErrors) + require.Nil(t, runResult.ExecutionError) + expectedResult := "Regular replace package loaded.\nVerification succeeded. Value is '\"another-dependency-loaded-from-main\"'.\n" + require.Equal(t, expectedResult, string(runResult.RunOutput)) + +} diff --git a/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_package_with_module_in_directory_test.go b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_package_with_module_in_directory_test.go new file mode 100644 index 0000000000..ae9b463c83 --- /dev/null +++ b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_package_with_module_in_directory_test.go @@ -0,0 +1,24 @@ +package startosis_replace_test + +import ( + "context" + "github.com/stretchr/testify/require" +) + +const ( + packageWithReplaceModuleInDirectoryRelPath = "../../../starlark/packages-with-replace/replace-with-module-in-directory" + packageWithReplaceModuleInDirectoryParams = `{ "message_origin" : "another-sample" }` +) + +func (suite *StartosisReplaceTestSuite) TestStartosisReplaceWithModuleInDirectory() { + ctx := context.Background() + runResult, _ := suite.RunPackageWithParams(ctx, packageWithReplaceModuleInDirectoryRelPath, packageWithReplaceModuleInDirectoryParams) + + t := suite.T() + require.Nil(t, runResult.InterpretationError) + require.Empty(t, runResult.ValidationErrors) + require.Nil(t, runResult.ExecutionError) + expectedResult := "Replace with module in directory sample package loaded.\nVerification succeeded. Value is '\"another-dependency-loaded-from-internal-module-in-main-branch\"'.\n" + require.Regexp(t, expectedResult, string(runResult.RunOutput)) + +} diff --git a/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_testsuite_test.go b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_testsuite_test.go new file mode 100644 index 0000000000..9636c6194d --- /dev/null +++ b/internal_testsuites/golang/testsuite/startosis_replace_test/startosis_replace_testsuite_test.go @@ -0,0 +1,68 @@ +package startosis_replace_test + +import ( + "context" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/starlark_run_config" + "os" + "path" + "testing" + + "github.com/kurtosis-tech/kurtosis-cli/golang_internal_testsuite/test_helpers" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +const ( + name = "startosis-replace" + emptyRunParams = "{}" +) + +type StartosisReplaceTestSuite struct { + suite.Suite + enclaveCtx *enclaves.EnclaveContext + destroyEnclaveFunc func() error +} + +func TestStartosisReplaceTestSuite(t *testing.T) { + suite.Run(t, new(StartosisReplaceTestSuite)) +} + +func (suite *StartosisReplaceTestSuite) SetupTest() { + ctx := context.Background() + t := suite.T() + enclaveCtx, _, destroyEnclaveFunc, err := test_helpers.CreateEnclave(t, ctx, name) + require.NoError(t, err, "An error occurred creating an enclave") + suite.enclaveCtx = enclaveCtx + suite.destroyEnclaveFunc = destroyEnclaveFunc +} + +func (suite *StartosisReplaceTestSuite) TearDownTest() { + err := suite.destroyEnclaveFunc() + require.NoError(suite.T(), err, "Destroying the test suite's enclave process has failed, you will have to remove it manually") +} + +func (suite *StartosisReplaceTestSuite) RunPackage(ctx context.Context, packageRelativeDirpath string) (*enclaves.StarlarkRunResult, error) { + return suite.RunPackageWithParams(ctx, packageRelativeDirpath, emptyRunParams) +} + +func (suite *StartosisReplaceTestSuite) RunRemotePackage(ctx context.Context, remotePackage string) (*enclaves.StarlarkRunResult, error) { + return suite.enclaveCtx.RunStarlarkRemotePackageBlocking(ctx, remotePackage, starlark_run_config.NewRunStarlarkConfig()) +} + +func (suite *StartosisReplaceTestSuite) RunPackageWithParams(ctx context.Context, packageRelativeDirpath string, params string) (*enclaves.StarlarkRunResult, error) { + logrus.Infof("Executing Startosis package...") + + currentWorkingDirectory, err := os.Getwd() + require.Nil(suite.T(), err) + packageDirpath := path.Join(currentWorkingDirectory, packageRelativeDirpath) + + logrus.Debugf("Startosis package dirpath: %v", packageDirpath) + + return suite.enclaveCtx.RunStarlarkPackageBlocking( + ctx, + packageDirpath, + starlark_run_config.NewRunStarlarkConfig(starlark_run_config.WithSerializedParams(params)), + ) +} diff --git a/internal_testsuites/starlark/packages-with-replace/regular-replace/kurtosis.yml b/internal_testsuites/starlark/packages-with-replace/regular-replace/kurtosis.yml new file mode 100644 index 0000000000..13d94c1ebe --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/regular-replace/kurtosis.yml @@ -0,0 +1,4 @@ +name: github.com/kurtosis-tech/sample-startosis-load/regular-replace +replace: + # Replacing the package with the 'another-sample' package + github.com/kurtosis-tech/sample-dependency-package: github.com/kurtosis-tech/another-sample-dependency-package diff --git a/internal_testsuites/starlark/packages-with-replace/regular-replace/main.star b/internal_testsuites/starlark/packages-with-replace/regular-replace/main.star new file mode 100644 index 0000000000..92729bd3cd --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/regular-replace/main.star @@ -0,0 +1,28 @@ +dependency = import_module("github.com/kurtosis-tech/sample-dependency-package/main.star") + +EXPECTED_MSG_FROM_MAIN = "dependency-loaded-from-main" +EXPECTED_MSG_FROM_ANOTHER_SAMPLE_MAIN = "another-dependency-loaded-from-main" + +MSG_ORIGIN_MAIN = "main" +MSG_ORIGIN_ANOTHER_SAMPLE_MAIN = "another-main" + +# TODO remove https://github.com/kurtosis-tech/sample-startosis-load/tree/main/sample-package if it's not used +def run(plan, message_origin=MSG_ORIGIN_MAIN): + plan.print("Regular replace package loaded.") + + msg_from_dependency = dependency.get_msg() + + if message_origin == MSG_ORIGIN_MAIN: + expected_msg = EXPECTED_MSG_FROM_MAIN + elif message_origin == MSG_ORIGIN_ANOTHER_SAMPLE_MAIN: + expected_msg = EXPECTED_MSG_FROM_ANOTHER_SAMPLE_MAIN + else: + expected_msg = "" + + plan.verify( + value = expected_msg, + assertion = "==", + target_value = msg_from_dependency, + ) + + return diff --git a/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/kurtosis.yml b/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/kurtosis.yml new file mode 100644 index 0000000000..1da79e36e1 --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/kurtosis.yml @@ -0,0 +1,4 @@ +name: github.com/kurtosis-tech/sample-startosis-load/replace-subpackage +replace: + # Replacing the package with the 'another-sample' package + github.com/kurtosis-tech/sample-dependency-package: github.com/kurtosis-tech/another-sample-dependency-package diff --git a/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/main.star b/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/main.star new file mode 100644 index 0000000000..c2a97c59d1 --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/replace-with-module-in-directory/main.star @@ -0,0 +1,27 @@ +internal_dependency = import_module("github.com/kurtosis-tech/sample-dependency-package/directory/internal-module.star") + +EXPECTED_MSG_FROM_INTERNAL_MODULE_MAIN = "dependency-loaded-from-internal-module-in-main-branch" +EXPECTED_MSG_FROM_ANOTHER_PACKAGE_INTERNAL_MODULE_MAIN = "another-dependency-loaded-from-internal-module-in-main-branch" + +MSG_ORIGIN_FROM_SAMPLE = "sample" +MSG_ORIGIN_FROM_ANOTHER_SAMPLE = "another-sample" + +def run(plan, message_origin=MSG_ORIGIN_FROM_SAMPLE): + plan.print("Replace with module in directory sample package loaded.") + + msg_from_dependency = internal_dependency.get_msg() + + if message_origin == MSG_ORIGIN_FROM_SAMPLE: + expected_msg = EXPECTED_MSG_FROM_INTERNAL_MODULE_MAIN + elif message_origin == MSG_ORIGIN_FROM_ANOTHER_SAMPLE: + expected_msg = EXPECTED_MSG_FROM_ANOTHER_PACKAGE_INTERNAL_MODULE_MAIN + else: + expected_msg = "" + + plan.verify( + value = expected_msg, + assertion = "==", + target_value = msg_from_dependency, + ) + + return diff --git a/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/kurtosis.yml b/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/kurtosis.yml new file mode 100644 index 0000000000..e00d577c7e --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/kurtosis.yml @@ -0,0 +1,4 @@ +name: github.com/kurtosis-tech/sample-startosis-load/replace-subpackage +replace: + # Replacing the package with the 'another branch' in the same package + github.com/kurtosis-tech/sample-dependency-package: github.com/kurtosis-tech/sample-dependency-package@test-branch diff --git a/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/main.star b/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/main.star new file mode 100644 index 0000000000..e2cfa745df --- /dev/null +++ b/internal_testsuites/starlark/packages-with-replace/replace-with-no-main-branch/main.star @@ -0,0 +1,28 @@ +dependency = import_module("github.com/kurtosis-tech/sample-dependency-package/main.star") + +EXPECTED_MSG_FROM_MAIN = "dependency-loaded-from-main" +EXPECTED_MSG_FROM_BRANCH = "dependency-loaded-from-test-branch" + +MSG_ORIGIN_MAIN = "main" +MSG_ORIGIN_BRANCH = "branch" + +# TODO remove https://github.com/kurtosis-tech/sample-startosis-load/tree/main/sample-package if it's not used +def run(plan, message_origin=MSG_ORIGIN_MAIN): + plan.print("Replace with no main branch package loaded.") + + msg_from_dependency = dependency.get_msg() + + if message_origin == MSG_ORIGIN_MAIN: + expected_msg = EXPECTED_MSG_FROM_MAIN + elif message_origin == MSG_ORIGIN_BRANCH: + expected_msg = EXPECTED_MSG_FROM_BRANCH + else: + expected_msg = "" + + plan.verify( + value = expected_msg, + assertion = "==", + target_value = msg_from_dependency, + ) + + return