Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Feb 28, 2024
1 parent 5e73caf commit 55f08af
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ type InterpretationTimeValueStore struct {
func CreateInterpretationTimeValueStore(enclaveDb *enclave_db.EnclaveDB, serde *kurtosis_types.StarlarkValueSerde) (*InterpretationTimeValueStore, error) {
serviceValuesRepository, err := getOrCreateNewServiceInterpretationTimeValueRepository(enclaveDb, serde)
if err != nil {
return nil, stacktrace.Propagate(err, "an error occurred creating interpretation time service value repository")
return nil, stacktrace.Propagate(err, "An error occurred creating interpretation time value store")
}
return &InterpretationTimeValueStore{serviceValues: serviceValuesRepository, serde: serde}, nil
}

func (itvs *InterpretationTimeValueStore) AddService(name service.ServiceName, service *kurtosis_types.Service) error {
if err := itvs.serviceValues.AddService(name, service); err != nil {
return stacktrace.Propagate(err, "an error occurred while adding '%v' for service '%v' to db", service, name)
return stacktrace.Propagate(err, "An error occurred while adding value '%v' for service '%v' to db", service, name)
}
return nil
}

func (itvs *InterpretationTimeValueStore) GetService(name service.ServiceName) (*kurtosis_types.Service, error) {
serviceStarlark, err := itvs.serviceValues.GetService(name)
if err != nil {
return nil, stacktrace.Propagate(err, "an error occurred fetching interpretation time value for '%v' from db", name)
return nil, stacktrace.Propagate(err, "An error occurred fetching interpretation time value for '%v' from db", name)
}
return serviceStarlark, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ type serviceInterpretationValueRepository struct {
starlarkValueSerde *kurtosis_types.StarlarkValueSerde
}

// TODO add tests for this module
func getOrCreateNewServiceInterpretationTimeValueRepository(
enclaveDb *enclave_db.EnclaveDB,
starlarkValueSerde *kurtosis_types.StarlarkValueSerde,
) (*serviceInterpretationValueRepository, error) {
if err := enclaveDb.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(serviceInterpretationValueBucketName)
if err != nil {
return stacktrace.Propagate(err, "An error occurred while creating the recipe result database bucket")
return stacktrace.Propagate(err, "An error occurred while creating the bucket for the service interpretation time value repository")
}
logrus.Debugf("Recipe result bucket: '%+v'", bucket)

return nil
}); err != nil {
return nil, stacktrace.Propagate(err, "An error occurred while building the recipe result repository")
return nil, stacktrace.Propagate(err, "An error occurred while building service interpretation time value repository")
}

repository := &serviceInterpretationValueRepository{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAddAndGetTest(t *testing.T) {
maybeUrl := ""

port, interpretationErr := port_spec.CreatePortSpecUsingGoValues(
"my-test-service",
string(serviceName),
uint16(443),
port_spec_core.TransportProtocol_TCP,
&applicationProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (builtin *AddServiceCapabilities) Interpret(locatorOfModuleInWhichThisBuilt

err = builtin.interpretationTimeValueStore.AddService(builtin.serviceName, returnValue)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "an error occurred while persisting return value for service '%v'", serviceName)
return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while persisting return value for service '%v'", serviceName)
}
return returnValue, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (builtin *AddServicesCapabilities) Interpret(locatorOfModuleInWhichThisBuil
builtin.serviceConfigs = serviceConfigs
builtin.readyConditions = readyConditions

resultUuids, returnValue, interpretationErr := makeAddServicesInterpretationReturnValue(builtin.serviceConfigs, builtin.runtimeValueStore, builtin.interpretationTimeValueStore)
resultUuids, returnValue, interpretationErr := makeAndPersistAddServicesInterpretationReturnValue(builtin.serviceConfigs, builtin.runtimeValueStore, builtin.interpretationTimeValueStore)
if interpretationErr != nil {
return nil, interpretationErr
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (builtin *AddServicesCapabilities) Execute(ctx context.Context, _ *builtin_
serviceMsg := fmt.Sprintf("Service '%v' error:\n%v\n", serviceName, serviceErr)
allServiceChecksErrMsg = allServiceChecksErrMsg + serviceMsg
}
return "", stacktrace.NewError("An error occurred while checking al service, these are the errors by service:\n%s", allServiceChecksErrMsg)
return "", stacktrace.NewError("An error occurred while checking all service, these are the errors by service:\n%s", allServiceChecksErrMsg)
}
defer func() {
if shouldDeleteAllStartedServices {
Expand Down Expand Up @@ -454,7 +454,7 @@ func validateAndConvertConfigsAndReadyConditions(
return convertedServiceConfigs, readyConditionsByServiceName, nil
}

func makeAddServicesInterpretationReturnValue(serviceConfigs map[service.ServiceName]*service.ServiceConfig, runtimeValueStore *runtime_value_store.RuntimeValueStore, interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore) (map[service.ServiceName]string, *starlark.Dict, *startosis_errors.InterpretationError) {
func makeAndPersistAddServicesInterpretationReturnValue(serviceConfigs map[service.ServiceName]*service.ServiceConfig, runtimeValueStore *runtime_value_store.RuntimeValueStore, interpretationTimeValueStore *interpretation_time_value_store.InterpretationTimeValueStore) (map[service.ServiceName]string, *starlark.Dict, *startosis_errors.InterpretationError) {
servicesObjectDict := starlark.NewDict(len(serviceConfigs))
resultUuids := map[service.ServiceName]string{}
var err error
Expand All @@ -472,7 +472,7 @@ func makeAddServicesInterpretationReturnValue(serviceConfigs map[service.Service
return nil, nil, startosis_errors.WrapWithInterpretationError(err, "Unable to generate the object that should be returned by the '%s' builtin", AddServicesBuiltinName)
}
if err = interpretationTimeValueStore.AddService(serviceName, serviceObject); err != nil {
return nil, nil, startosis_errors.WrapWithInterpretationError(err, "an error occurred while persisting the return value for service with name '%v'", serviceName)
return nil, nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while persisting the return value for service with name '%v'", serviceName)
}
}
return resultUuids, servicesObjectDict, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (builtin *GetServiceCapabilities) Interpret(_ string, arguments *builtin_ar

serviceStarlarkValue, err := builtin.interpretationTimeStore.GetService(serviceName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "an error occurred while fetching service '%v' from the store", serviceName)
return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while fetching service '%v' from the store", serviceName)
}

return serviceStarlarkValue, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (suite *StartosisAddServiceTestSuite) TestAddTwoServicesAndTestConnection()
expectedScriptOutput := `Adding services ` + serviceName + ` and ` + serviceName2 + `
Service '` + serviceName + `' added with service UUID '[a-z-0-9]+'
Service '` + serviceName2 + `' added with service UUID '[a-z-0-9]+'
Fetched service '` + "" + `'
Fetched service '` + serviceName + `'
Service\(name="datastore-1", hostname="datastore-1", ip_address="[0-9\.]+", ports=\{"grpc": PortSpec\(number=1323, transport_protocol="TCP", wait="2m0s"\)\}\)
Command returned with exit code '0' and the following output:
--------------------
Expand Down

0 comments on commit 55f08af

Please sign in to comment.