-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move configuration values to AzureConfig type in azure helper package…
…, in order to reuse the code between both operators. Input configuration is unchanged due to yaml:",inline"
- Loading branch information
Showing
6 changed files
with
277 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// AzureConfig is the configuration of a Azure Event Hub input operator. | ||
type AzureConfig struct { | ||
// required | ||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` | ||
Name string `json:"name,omitempty" yaml:"name,omitempty"` | ||
Group string `json:"group,omitempty" yaml:"group,omitempty"` | ||
ConnectionString string `json:"connection_string,omitempty" yaml:"connection_string,omitempty"` | ||
|
||
// optional | ||
PrefetchCount uint32 `json:"prefetch_count,omitempty" yaml:"prefetch_count,omitempty"` | ||
StartAt string `json:"start_at,omitempty" yaml:"start_at,omitempty"` | ||
} | ||
|
||
func (a AzureConfig) Validate() error { | ||
if a.Namespace == "" { | ||
return fmt.Errorf("missing required parameter 'namespace'") | ||
} | ||
|
||
if a.Name == "" { | ||
return fmt.Errorf("missing required parameter 'name'") | ||
} | ||
|
||
if a.Group == "" { | ||
return fmt.Errorf("missing required parameter 'group'") | ||
} | ||
|
||
if a.ConnectionString == "" { | ||
return fmt.Errorf("missing required parameter 'connection_string'") | ||
} | ||
|
||
if a.PrefetchCount < 1 { | ||
return fmt.Errorf("invalid value for parameter 'prefetch_count'") | ||
} | ||
|
||
if a.StartAt != "beginning" && a.StartAt != "end" { | ||
return fmt.Errorf("invalid value for parameter 'start_at'") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidate(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input AzureConfig | ||
expectErr bool | ||
}{ | ||
{ | ||
"missing-namespace", | ||
AzureConfig{ | ||
Namespace: "", | ||
Name: "john", | ||
Group: "devel", | ||
ConnectionString: "some connection string", | ||
StartAt: "end", | ||
PrefetchCount: 10, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"missing-name", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "", | ||
Group: "devel", | ||
ConnectionString: "some connection string", | ||
StartAt: "end", | ||
PrefetchCount: 10, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"missing-group", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "", | ||
ConnectionString: "some connection string", | ||
StartAt: "end", | ||
PrefetchCount: 10, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"missing-connection-string", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "dev", | ||
ConnectionString: "", | ||
StartAt: "end", | ||
PrefetchCount: 10, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"invalid-prefetch-count", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "dev", | ||
ConnectionString: "some string", | ||
StartAt: "end", | ||
PrefetchCount: 0, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"invalid-start-at", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "dev", | ||
ConnectionString: "some string", | ||
StartAt: "bad", | ||
PrefetchCount: 10, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"valid-start-at-end", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "dev", | ||
ConnectionString: "some string", | ||
StartAt: "end", | ||
PrefetchCount: 10, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid-start-at-beginning", | ||
AzureConfig{ | ||
Namespace: "namespace", | ||
Name: "dev", | ||
Group: "dev", | ||
ConnectionString: "some string", | ||
PrefetchCount: 10, | ||
StartAt: "beginning", | ||
}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.input.Validate() | ||
if tc.expectErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.