-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: err gracefully when config job spec is non string (#513)
- Loading branch information
1 parent
7d24318
commit 7253693
Showing
2 changed files
with
84 additions
and
2 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
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 |
---|---|---|
|
@@ -236,6 +236,80 @@ hooks: []` | |
assert.Equal(t, expErr, actualErr) | ||
assert.Equal(t, models.JobSpec{}, modelJob) | ||
}) | ||
t.Run("should not convert job if task config is not string", func(t *testing.T) { | ||
yamlSpec := ` | ||
version: 1 | ||
name: test_job | ||
owner: [email protected] | ||
schedule: | ||
start_date: "2021-02-03" | ||
interval: 0 2 * * * | ||
behavior: | ||
depends_on_past: true | ||
catch_up: false | ||
notify: | ||
- on: test | ||
channel: | ||
- test://hello | ||
task: | ||
name: bq2bq | ||
config: | ||
PROJECT: example | ||
DATASET: dataset | ||
TABLE: table | ||
SQL_TYPE: STANDARD | ||
LOAD_METHOD: REPLACE | ||
MAX_LINE: 100 | ||
window: | ||
size: 168h | ||
offset: 0 | ||
truncate_to: w | ||
labels: | ||
orchestrator: optimus | ||
dependencies: | ||
- | ||
http: | ||
name: http-sensor-1 | ||
headers: | ||
Authentication: Token-1 | ||
Content-type: application/json | ||
params: | ||
key-1: value-1 | ||
key-2: value-2 | ||
url: "https://optimus-host:80/serve/1/" | ||
- | ||
http: | ||
name: http-sensor-2 | ||
headers: | ||
Authentication: Token-2 | ||
Content-type: application/json | ||
params: | ||
key-3: value-3 | ||
key-4: value-4 | ||
url: "https://optimus-host:80/serve/2/" | ||
hooks: []` | ||
var localJobParsed local.Job | ||
err := yaml.Unmarshal([]byte(yamlSpec), &localJobParsed) | ||
assert.Nil(t, err) | ||
|
||
execUnit := new(mock.BasePlugin) | ||
execUnit.On("PluginInfo").Return(&models.PluginInfoResponse{ | ||
Name: "bq2bq", | ||
}, nil) | ||
|
||
pluginRepo := new(mock.SupportedPluginRepo) | ||
pluginRepo.On("GetByName", "bq2bq").Return(&models.Plugin{ | ||
Base: execUnit, | ||
}, nil) | ||
adapter := local.NewJobSpecAdapter(pluginRepo) | ||
|
||
modelJob, actualErr := adapter.ToSpec(localJobParsed) | ||
|
||
expErr := fmt.Errorf("spec reading error, failed to convert value 100 on key MAX_LINE to string") | ||
assert.Equal(t, expErr, actualErr) | ||
assert.Equal(t, models.JobSpec{}, modelJob) | ||
}) | ||
} | ||
|
||
func TestJob_MergeFrom(t *testing.T) { | ||
|