Skip to content

Commit 17b9bd3

Browse files
committed
Update testserver to validate git_provider
Enables no-git-provider test on local.
1 parent d7b6edb commit 17b9bd3

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

acceptance/bundle/resources/jobs/no-git-provider/out.test.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acceptance/bundle/resources/jobs/no-git-provider/test.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Local = false
1+
Local = true
22
Cloud = true
33

44
RecordRequests = false

libs/testserver/jobs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/databricks/databricks-sdk-go/service/jobs"
1818
)
1919

20+
const missingJobGitProviderMessage = "git_source.git_provider must be one of: github,gitlab,bitbucketcloud,gitlabenterpriseedition,bitbucketserver,azuredevopsservices,githubenterprise,awscodecommit"
21+
2022
// venvPython returns the path to the Python executable in a venv.
2123
// On Unix: venv/bin/python
2224
// On Windows: venv\Scripts\python.exe
@@ -27,6 +29,22 @@ func venvPython(venvDir string) string {
2729
return filepath.Join(venvDir, "bin", "python")
2830
}
2931

32+
// validateJobGitSource mirrors Jobs API validation for git_source requests.
33+
func validateJobGitSource(gitSource *jobs.GitSource) *Response {
34+
if gitSource == nil || gitSource.GitProvider != "" {
35+
return nil
36+
}
37+
38+
response := Response{
39+
StatusCode: 400,
40+
Body: map[string]string{
41+
"error_code": "INVALID_PARAMETER_VALUE",
42+
"message": missingJobGitProviderMessage,
43+
},
44+
}
45+
return &response
46+
}
47+
3048
func (s *FakeWorkspace) JobsCreate(req Request) Response {
3149
var request jobs.CreateJob
3250
if err := json.Unmarshal(req.Body, &request); err != nil {
@@ -35,6 +53,9 @@ func (s *FakeWorkspace) JobsCreate(req Request) Response {
3553
Body: fmt.Sprintf("request parsing error: %s", err),
3654
}
3755
}
56+
if response := validateJobGitSource(request.GitSource); response != nil {
57+
return *response
58+
}
3859

3960
defer s.LockUnlock()()
4061

@@ -70,6 +91,9 @@ func (s *FakeWorkspace) JobsReset(req Request) Response {
7091
Body: fmt.Sprintf("request parsing error: %s", err),
7192
}
7293
}
94+
if response := validateJobGitSource(request.NewSettings.GitSource); response != nil {
95+
return *response
96+
}
7397

7498
defer s.LockUnlock()()
7599

0 commit comments

Comments
 (0)