Skip to content

Commit

Permalink
fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwahiremat committed Sep 18, 2023
1 parent b8f9d40 commit 2984d12
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 117 deletions.
2 changes: 1 addition & 1 deletion pkg/corerp/processors/extenders/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *Processor) Delete(ctx context.Context, resource *datamodel.Extender, op
return nil
}

func mergeOutputValues(properties map[string]any, recipeOutput *recipes.RecipeOutput, secret bool) map[string]any {
func mergeOutputValues(properties map[string]any, recipeOutput *recipes.RecipeOutputResponse, secret bool) map[string]any {
values := make(map[string]any)
for k, val := range properties {
values[k] = val
Expand Down
8 changes: 4 additions & 4 deletions pkg/corerp/processors/extenders/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"bucketName": "myBucket",
Expand Down Expand Up @@ -144,7 +144,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand Down Expand Up @@ -190,7 +190,7 @@ func Test_Process(t *testing.T) {
},
},
}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand Down Expand Up @@ -225,7 +225,7 @@ func Test_MergeOutputValues(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"region": "westus",
Expand Down
4 changes: 2 additions & 2 deletions pkg/daprrp/processors/pubsubbrokers/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
Expand Down Expand Up @@ -246,7 +246,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,

// Values and secrets will be overridden by the resource.
Expand Down
4 changes: 2 additions & 2 deletions pkg/daprrp/processors/secretstores/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
Expand Down Expand Up @@ -231,7 +231,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,

// Values and secrets will be overridden by the resource.
Expand Down
4 changes: 2 additions & 2 deletions pkg/daprrp/processors/statestores/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
Expand Down Expand Up @@ -238,7 +238,7 @@ func Test_Process(t *testing.T) {
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,

// Values and secrets will be overridden by the resource.
Expand Down
6 changes: 3 additions & 3 deletions pkg/datastoresrp/processors/mongodatabases/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"host": host,
Expand Down Expand Up @@ -179,7 +179,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand Down Expand Up @@ -241,7 +241,7 @@ func Test_Process(t *testing.T) {

t.Run("failure - missing required values", func(t *testing.T) {
resource := &datamodel.MongoDatabase{}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/datastoresrp/processors/rediscaches/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"host": host,
Expand Down Expand Up @@ -189,7 +189,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand Down Expand Up @@ -254,7 +254,7 @@ func Test_Process(t *testing.T) {

t.Run("failure - missing required values", func(t *testing.T) {
resource := &datamodel.RedisCache{}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/datastoresrp/processors/sqldatabases/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"database": database,
Expand Down Expand Up @@ -166,7 +166,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand Down Expand Up @@ -227,7 +227,7 @@ func Test_Process(t *testing.T) {

t.Run("failure - missing required values", func(t *testing.T) {
resource := &datamodel.SqlDatabase{}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/messagingrp/processors/rabbitmqqueues/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"queue": queue,
Expand Down Expand Up @@ -148,7 +148,7 @@ func Test_Process(t *testing.T) {
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand Down Expand Up @@ -196,7 +196,7 @@ func Test_Process(t *testing.T) {

t.Run("failure - missing required values", func(t *testing.T) {
resource := &datamodel.RabbitMQQueue{}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *CreateOrUpdateResource[P, T]) copyOutputResources(data P) []string {
return previousOutputResources
}

func (c *CreateOrUpdateResource[P, T]) executeRecipeIfNeeded(ctx context.Context, data P, prevState []string) (*recipes.RecipeOutput, error) {
func (c *CreateOrUpdateResource[P, T]) executeRecipeIfNeeded(ctx context.Context, data P, prevState []string) (*recipes.RecipeOutputResponse, error) {
// 'any' is required here to convert to an interface type, only then can we use a type assertion.
recipeDataModel, supportsRecipes := any(data).(datamodel.RecipeDataModel)
if !supportsRecipes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestCreateOrUpdateResource_Run(t *testing.T) {
},
PreviousState: prevState,
}).
Return(&recipes.RecipeOutput{}, tt.recipeErr).
Return(&recipes.RecipeOutputResponse{}, tt.recipeErr).
Times(1)
} else if stillPassing {
eng.EXPECT().
Expand All @@ -360,7 +360,7 @@ func TestCreateOrUpdateResource_Run(t *testing.T) {
},
PreviousState: prevState,
}).
Return(&recipes.RecipeOutput{}, nil).
Return(&recipes.RecipeOutputResponse{}, nil).
Times(1)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/portableresources/processors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Options struct {
RuntimeConfiguration recipes.RuntimeConfiguration

// RecipeOutput represents the output of executing a recipe (may be nil).
RecipeOutput *recipes.RecipeOutput
RecipeOutput *recipes.RecipeOutputResponse
}

// ValidationError represents a user-facing validation message reported by the processor.
Expand Down
10 changes: 5 additions & 5 deletions pkg/portableresources/processors/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const (
// - Apply values and secrets from the recipe output to the resource data model.
type Validator struct {
resourcesField *[]*portableresources.ResourceReference
fields []func(output *recipes.RecipeOutput) string
computedFields []func(output *recipes.RecipeOutput) string
fields []func(output *recipes.RecipeOutputResponse) string
computedFields []func(output *recipes.RecipeOutputResponse) string

// ConnectionValues stores the connection values extracted from the data model and recipe output.
ConnectionValues map[string]any
Expand Down Expand Up @@ -150,7 +150,7 @@ func (v *Validator) AddComputedSecretField(name string, ref *string, compute fun
// This function returns *ValidationError for validation failures.
//
// After calling SetAndValidate, the connection values/secrets and output resources will be populated.
func (v *Validator) SetAndValidate(output *recipes.RecipeOutput) error {
func (v *Validator) SetAndValidate(output *recipes.RecipeOutputResponse) error {
msgs := []string{}

if output != nil {
Expand Down Expand Up @@ -201,8 +201,8 @@ func (v *Validator) SetAndValidate(output *recipes.RecipeOutput) error {
return nil
}

func bind[T any](v *Validator, name string, ref *T, required bool, secret bool, typeName string, convert func(value any) (T, bool), compute func() (T, *ValidationError)) func(output *recipes.RecipeOutput) string {
return func(output *recipes.RecipeOutput) string {
func bind[T any](v *Validator, name string, ref *T, required bool, secret bool, typeName string, convert func(value any) (T, bool), compute func() (T, *ValidationError)) func(output *recipes.RecipeOutputResponse) string {
return func(output *recipes.RecipeOutputResponse) string {
valueKind := kindConnectionValue
propertyPath := fmt.Sprintf(".properties.%v", name)
if secret {
Expand Down
Loading

0 comments on commit 2984d12

Please sign in to comment.