From 73990fa5d2b956643698fa619b19ff63b60c882f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Ma=C5=BEgon?= Date: Thu, 15 Feb 2024 18:15:22 +0100 Subject: [PATCH] rename proto folder parameter to config --- config/proto.go | 66 +++++++------- config/proto_test.go | 86 +++++++++---------- .../{parameter => config}/v1/parameter.pb.go | 0 .../{parameter => config}/v1/parameter.proto | 0 4 files changed, 76 insertions(+), 76 deletions(-) rename proto/{parameter => config}/v1/parameter.pb.go (100%) rename proto/{parameter => config}/v1/parameter.proto (100%) diff --git a/config/proto.go b/config/proto.go index e0c94e8..defd048 100644 --- a/config/proto.go +++ b/config/proto.go @@ -20,29 +20,29 @@ import ( "strconv" "strings" - parameterv1 "github.com/conduitio/conduit-commons/proto/parameter/v1" + configv1 "github.com/conduitio/conduit-commons/proto/config/v1" ) func _() { // An "invalid array index" compiler error signifies that the constant values have changed. var cTypes [1]struct{} - _ = cTypes[int(ParameterTypeString)-int(parameterv1.Parameter_TYPE_STRING)] - _ = cTypes[int(ParameterTypeInt)-int(parameterv1.Parameter_TYPE_INT)] - _ = cTypes[int(ParameterTypeFloat)-int(parameterv1.Parameter_TYPE_FLOAT)] - _ = cTypes[int(ParameterTypeBool)-int(parameterv1.Parameter_TYPE_BOOL)] - _ = cTypes[int(ParameterTypeFile)-int(parameterv1.Parameter_TYPE_FILE)] - _ = cTypes[int(ParameterTypeDuration)-int(parameterv1.Parameter_TYPE_DURATION)] + _ = cTypes[int(ParameterTypeString)-int(configv1.Parameter_TYPE_STRING)] + _ = cTypes[int(ParameterTypeInt)-int(configv1.Parameter_TYPE_INT)] + _ = cTypes[int(ParameterTypeFloat)-int(configv1.Parameter_TYPE_FLOAT)] + _ = cTypes[int(ParameterTypeBool)-int(configv1.Parameter_TYPE_BOOL)] + _ = cTypes[int(ParameterTypeFile)-int(configv1.Parameter_TYPE_FILE)] + _ = cTypes[int(ParameterTypeDuration)-int(configv1.Parameter_TYPE_DURATION)] } func _() { // An "invalid array index" compiler error signifies that the constant values have changed. var cTypes [1]struct{} - _ = cTypes[int(ValidationTypeRequired)-int(parameterv1.Validation_TYPE_REQUIRED)] - _ = cTypes[int(ValidationTypeGreaterThan)-int(parameterv1.Validation_TYPE_GREATER_THAN)] - _ = cTypes[int(ValidationTypeLessThan)-int(parameterv1.Validation_TYPE_LESS_THAN)] - _ = cTypes[int(ValidationTypeInclusion)-int(parameterv1.Validation_TYPE_INCLUSION)] - _ = cTypes[int(ValidationTypeExclusion)-int(parameterv1.Validation_TYPE_EXCLUSION)] - _ = cTypes[int(ValidationTypeRegex)-int(parameterv1.Validation_TYPE_REGEX)] + _ = cTypes[int(ValidationTypeRequired)-int(configv1.Validation_TYPE_REQUIRED)] + _ = cTypes[int(ValidationTypeGreaterThan)-int(configv1.Validation_TYPE_GREATER_THAN)] + _ = cTypes[int(ValidationTypeLessThan)-int(configv1.Validation_TYPE_LESS_THAN)] + _ = cTypes[int(ValidationTypeInclusion)-int(configv1.Validation_TYPE_INCLUSION)] + _ = cTypes[int(ValidationTypeExclusion)-int(configv1.Validation_TYPE_EXCLUSION)] + _ = cTypes[int(ValidationTypeRegex)-int(configv1.Validation_TYPE_REGEX)] } // -- From Proto To Parameter -------------------------------------------------- @@ -50,7 +50,7 @@ func _() { // FromProto takes data from the supplied proto object and populates the // receiver. If the proto object is nil, the receiver is set to its zero value. // If the function returns an error, the receiver could be partially populated. -func (p *Parameters) FromProto(proto map[string]*parameterv1.Parameter) error { +func (p *Parameters) FromProto(proto map[string]*configv1.Parameter) error { if proto == nil { *p = nil return nil @@ -71,7 +71,7 @@ func (p *Parameters) FromProto(proto map[string]*parameterv1.Parameter) error { // FromProto takes data from the supplied proto object and populates the // receiver. If the proto object is nil, the receiver is set to its zero value. // If the function returns an error, the receiver could be partially populated. -func (p *Parameter) FromProto(proto *parameterv1.Parameter) error { +func (p *Parameter) FromProto(proto *configv1.Parameter) error { if proto == nil { *p = Parameter{} return nil @@ -89,7 +89,7 @@ func (p *Parameter) FromProto(proto *parameterv1.Parameter) error { return nil } -func validationsFromProto(proto []*parameterv1.Validation) ([]Validation, error) { +func validationsFromProto(proto []*configv1.Validation) ([]Validation, error) { if proto == nil { return nil, nil } @@ -105,37 +105,37 @@ func validationsFromProto(proto []*parameterv1.Validation) ([]Validation, error) return validations, nil } -func validationFromProto(proto *parameterv1.Validation) (Validation, error) { +func validationFromProto(proto *configv1.Validation) (Validation, error) { if proto == nil { return nil, nil //nolint:nilnil // This is the expected behavior. } switch proto.Type { - case parameterv1.Validation_TYPE_REQUIRED: + case configv1.Validation_TYPE_REQUIRED: return ValidationRequired{}, nil - case parameterv1.Validation_TYPE_GREATER_THAN: + case configv1.Validation_TYPE_GREATER_THAN: v, err := strconv.ParseFloat(proto.Value, 64) if err != nil { return nil, fmt.Errorf("error parsing greater than value: %w", err) } return ValidationGreaterThan{V: v}, nil - case parameterv1.Validation_TYPE_LESS_THAN: + case configv1.Validation_TYPE_LESS_THAN: v, err := strconv.ParseFloat(proto.Value, 64) if err != nil { return nil, fmt.Errorf("error parsing less than value: %w", err) } return ValidationLessThan{V: v}, nil - case parameterv1.Validation_TYPE_INCLUSION: + case configv1.Validation_TYPE_INCLUSION: return ValidationInclusion{List: strings.Split(proto.Value, ",")}, nil - case parameterv1.Validation_TYPE_EXCLUSION: + case configv1.Validation_TYPE_EXCLUSION: return ValidationExclusion{List: strings.Split(proto.Value, ",")}, nil - case parameterv1.Validation_TYPE_REGEX: + case configv1.Validation_TYPE_REGEX: regex, err := regexp.Compile(proto.Value) if err != nil { return nil, fmt.Errorf("error compiling regex: %w", err) } return ValidationRegex{Regex: regex}, nil - case parameterv1.Validation_TYPE_UNSPECIFIED: + case configv1.Validation_TYPE_UNSPECIFIED: fallthrough default: return nil, fmt.Errorf("%v: %w", proto.Type, ErrInvalidValidationType) @@ -145,38 +145,38 @@ func validationFromProto(proto *parameterv1.Validation) (Validation, error) { // -- From Parameter To Proto -------------------------------------------------- // ToProto takes data from the receiver and populates the supplied proto object. -func (p Parameters) ToProto(proto map[string]*parameterv1.Parameter) { +func (p Parameters) ToProto(proto map[string]*configv1.Parameter) { clear(proto) for k, param := range p { - var v parameterv1.Parameter + var v configv1.Parameter param.ToProto(&v) proto[k] = &v } } // ToProto takes data from the receiver and populates the supplied proto object. -func (p Parameter) ToProto(proto *parameterv1.Parameter) { +func (p Parameter) ToProto(proto *configv1.Parameter) { proto.Default = p.Default proto.Description = p.Description - proto.Type = parameterv1.Parameter_Type(p.Type) + proto.Type = configv1.Parameter_Type(p.Type) proto.Validations = validationsToProto(p.Validations) } -func validationsToProto(validations []Validation) []*parameterv1.Validation { +func validationsToProto(validations []Validation) []*configv1.Validation { if validations == nil { return nil } - proto := make([]*parameterv1.Validation, len(validations)) + proto := make([]*configv1.Validation, len(validations)) for i, v := range validations { proto[i] = validationToProto(v) } return proto } -func validationToProto(validation Validation) *parameterv1.Validation { - return ¶meterv1.Validation{ - Type: parameterv1.Validation_Type(validation.Type()), +func validationToProto(validation Validation) *configv1.Validation { + return &configv1.Validation{ + Type: configv1.Validation_Type(validation.Type()), Value: validation.Value(), } } diff --git a/config/proto_test.go b/config/proto_test.go index 112a3a0..fcb2c70 100644 --- a/config/proto_test.go +++ b/config/proto_test.go @@ -19,24 +19,24 @@ import ( "regexp" "testing" - parameterv1 "github.com/conduitio/conduit-commons/proto/parameter/v1" + configv1 "github.com/conduitio/conduit-commons/proto/config/v1" "github.com/matryer/is" ) func TestParameter_FromProto(t *testing.T) { is := is.New(t) - have := ¶meterv1.Parameter{ + have := &configv1.Parameter{ Description: "test-description", Default: "test-default", - Type: parameterv1.Parameter_TYPE_STRING, - Validations: []*parameterv1.Validation{ - {Type: parameterv1.Validation_TYPE_REQUIRED}, - {Type: parameterv1.Validation_TYPE_GREATER_THAN, Value: "1.2"}, - {Type: parameterv1.Validation_TYPE_LESS_THAN, Value: "3.4"}, - {Type: parameterv1.Validation_TYPE_INCLUSION, Value: "1,2,3"}, - {Type: parameterv1.Validation_TYPE_EXCLUSION, Value: "4,5,6"}, - {Type: parameterv1.Validation_TYPE_REGEX, Value: "test-regex"}, + Type: configv1.Parameter_TYPE_STRING, + Validations: []*configv1.Validation{ + {Type: configv1.Validation_TYPE_REQUIRED}, + {Type: configv1.Validation_TYPE_GREATER_THAN, Value: "1.2"}, + {Type: configv1.Validation_TYPE_LESS_THAN, Value: "3.4"}, + {Type: configv1.Validation_TYPE_INCLUSION, Value: "1,2,3"}, + {Type: configv1.Validation_TYPE_EXCLUSION, Value: "4,5,6"}, + {Type: configv1.Validation_TYPE_REGEX, Value: "test-regex"}, }, } @@ -73,41 +73,41 @@ func TestParameter_ToProto(t *testing.T) { }, } - want := ¶meterv1.Parameter{ + want := &configv1.Parameter{ Description: "test-description", Default: "test-default", - Type: parameterv1.Parameter_TYPE_STRING, - Validations: []*parameterv1.Validation{ - {Type: parameterv1.Validation_TYPE_REQUIRED}, - {Type: parameterv1.Validation_TYPE_REGEX, Value: "test-regex"}, + Type: configv1.Parameter_TYPE_STRING, + Validations: []*configv1.Validation{ + {Type: configv1.Validation_TYPE_REQUIRED}, + {Type: configv1.Validation_TYPE_REGEX, Value: "test-regex"}, }, } - got := ¶meterv1.Parameter{} + got := &configv1.Parameter{} have.ToProto(got) is.Equal(want, got) } func TestParameter_ParameterTypes(t *testing.T) { testCases := []struct { - protoType parameterv1.Parameter_Type + protoType configv1.Parameter_Type goType ParameterType }{ - {protoType: parameterv1.Parameter_TYPE_UNSPECIFIED, goType: 0}, - {protoType: parameterv1.Parameter_TYPE_STRING, goType: ParameterTypeString}, - {protoType: parameterv1.Parameter_TYPE_INT, goType: ParameterTypeInt}, - {protoType: parameterv1.Parameter_TYPE_FLOAT, goType: ParameterTypeFloat}, - {protoType: parameterv1.Parameter_TYPE_BOOL, goType: ParameterTypeBool}, - {protoType: parameterv1.Parameter_TYPE_FILE, goType: ParameterTypeFile}, - {protoType: parameterv1.Parameter_TYPE_DURATION, goType: ParameterTypeDuration}, - {protoType: parameterv1.Parameter_Type(100), goType: 100}, + {protoType: configv1.Parameter_TYPE_UNSPECIFIED, goType: 0}, + {protoType: configv1.Parameter_TYPE_STRING, goType: ParameterTypeString}, + {protoType: configv1.Parameter_TYPE_INT, goType: ParameterTypeInt}, + {protoType: configv1.Parameter_TYPE_FLOAT, goType: ParameterTypeFloat}, + {protoType: configv1.Parameter_TYPE_BOOL, goType: ParameterTypeBool}, + {protoType: configv1.Parameter_TYPE_FILE, goType: ParameterTypeFile}, + {protoType: configv1.Parameter_TYPE_DURATION, goType: ParameterTypeDuration}, + {protoType: configv1.Parameter_Type(100), goType: 100}, } t.Run("FromProto", func(t *testing.T) { for _, tc := range testCases { t.Run(tc.goType.String(), func(*testing.T) { is := is.New(t) - have := ¶meterv1.Parameter{Type: tc.protoType} + have := &configv1.Parameter{Type: tc.protoType} want := Parameter{Type: tc.goType} var got Parameter @@ -123,9 +123,9 @@ func TestParameter_ParameterTypes(t *testing.T) { t.Run(tc.goType.String(), func(t *testing.T) { is := is.New(t) have := Parameter{Type: tc.goType} - want := ¶meterv1.Parameter{Type: tc.protoType} + want := &configv1.Parameter{Type: tc.protoType} - got := ¶meterv1.Parameter{} + got := &configv1.Parameter{} have.ToProto(got) is.Equal(want, got) }) @@ -135,31 +135,31 @@ func TestParameter_ParameterTypes(t *testing.T) { func TestParameter_Validation(t *testing.T) { testCases := []struct { - protoType *parameterv1.Validation + protoType *configv1.Validation goType Validation }{ { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_REQUIRED}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_REQUIRED}, goType: ValidationRequired{}, }, { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_GREATER_THAN, Value: "1.2"}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_GREATER_THAN, Value: "1.2"}, goType: ValidationGreaterThan{V: 1.2}, }, { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_LESS_THAN, Value: "3.4"}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_LESS_THAN, Value: "3.4"}, goType: ValidationLessThan{V: 3.4}, }, { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_INCLUSION, Value: "1,2,3"}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_INCLUSION, Value: "1,2,3"}, goType: ValidationInclusion{List: []string{"1", "2", "3"}}, }, { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_EXCLUSION, Value: "4,5,6"}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_EXCLUSION, Value: "4,5,6"}, goType: ValidationExclusion{List: []string{"4", "5", "6"}}, }, { - protoType: ¶meterv1.Validation{Type: parameterv1.Validation_TYPE_REGEX, Value: "test-regex"}, + protoType: &configv1.Validation{Type: configv1.Validation_TYPE_REGEX, Value: "test-regex"}, goType: ValidationRegex{Regex: regexp.MustCompile("test-regex")}, }, } @@ -168,8 +168,8 @@ func TestParameter_Validation(t *testing.T) { for _, tc := range testCases { t.Run(tc.goType.Type().String(), func(t *testing.T) { is := is.New(t) - have := ¶meterv1.Parameter{ - Validations: []*parameterv1.Validation{tc.protoType}, + have := &configv1.Parameter{ + Validations: []*configv1.Validation{tc.protoType}, } want := Parameter{ Validations: []Validation{tc.goType}, @@ -190,11 +190,11 @@ func TestParameter_Validation(t *testing.T) { have := Parameter{ Validations: []Validation{tc.goType}, } - want := ¶meterv1.Parameter{ - Validations: []*parameterv1.Validation{tc.protoType}, + want := &configv1.Parameter{ + Validations: []*configv1.Validation{tc.protoType}, } - got := ¶meterv1.Parameter{} + got := &configv1.Parameter{} have.ToProto(got) is.Equal(want, got) }) @@ -204,9 +204,9 @@ func TestParameter_Validation(t *testing.T) { func TestParameter_Validation_InvalidType(t *testing.T) { is := is.New(t) - have := ¶meterv1.Parameter{ - Validations: []*parameterv1.Validation{ - {Type: parameterv1.Validation_TYPE_UNSPECIFIED}, + have := &configv1.Parameter{ + Validations: []*configv1.Validation{ + {Type: configv1.Validation_TYPE_UNSPECIFIED}, }, } var got Parameter diff --git a/proto/parameter/v1/parameter.pb.go b/proto/config/v1/parameter.pb.go similarity index 100% rename from proto/parameter/v1/parameter.pb.go rename to proto/config/v1/parameter.pb.go diff --git a/proto/parameter/v1/parameter.proto b/proto/config/v1/parameter.proto similarity index 100% rename from proto/parameter/v1/parameter.proto rename to proto/config/v1/parameter.proto