Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit scheduler rules with project #151

Merged
merged 8 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions api/models/project_v1_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@ import (
yaml "gopkg.in/yaml.v2"
)

type Scheduler struct {
Name string `json:"name"`
Id string `json:"id,omitempty"`
Branch string `json:"branch"`
At string `json:"at"`
PipelineFile string `json:"pipeline_file" yaml:"pipeline_file"`
}

type ProjectV1Alpha struct {
ApiVersion string `json:"apiVersion,omitempty" yaml:"apiVersion"`
Kind string `json:"kind,omitempty" yaml:"kind"`
Metadata struct {
Name string `json:"name,omitempty"`
Id string `json:"id,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Id string `json:"id,omitempty"`
Description string `json:"description,omitempty"`
} `json:"metadata,omitempty"`

Spec struct {
Repository struct {
Url string `json:"url,omitempty"`
} `json:"repository,omitempty"`
Schedulers []Scheduler `json:"schedulers,omitempty" yaml:"schedulers,omitempty"`
} `json:"spec,omitempty"`
}

Expand Down
34 changes: 27 additions & 7 deletions cmd/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,20 @@ func Test__EditProject__Response200(t *testing.T) {
"spec":{
"repository":{
"url":"git@github.com/renderextext/hello"
}
},
"schedulers":[
{
"name":"cron",
"id":"bb2ba294-d4b3-48bc-90a7-12dd56e9424c",
"branch":"master",
"at":"* * * *",
"pipeline_file":".semaphore/cron.yml"
}
]
}
}`

received := false
var received *models.ProjectV1Alpha

httpmock.RegisterResponder("GET", "https://org.semaphoretext.xyz/api/v1alpha/projects/hello",
func(req *http.Request) (*http.Response, error) {
Expand All @@ -171,16 +180,27 @@ func Test__EditProject__Response200(t *testing.T) {

httpmock.RegisterResponder("PATCH", "https://org.semaphoretext.xyz/api/v1alpha/projects/bb2ba294-d4b3-48bc-90a7-12dd56e9424b",
func(req *http.Request) (*http.Response, error) {
received = true
body, _ := ioutil.ReadAll(req.Body)
received, _ = models.NewProjectV1AlphaFromJson(body)

return httpmock.NewStringResponse(200, dash), nil
return httpmock.NewStringResponse(200, string(body)), nil
},
)

RootCmd.SetArgs([]string{"edit", "project", "hello"})
RootCmd.Execute()

if received == false {
t.Error("Expected the API to receive GET and PATCH project")
}
assert.Equal(t, received.Metadata.Name, "hello")
assert.Equal(t, received.Metadata.Description, "Just saying hi!")

repo := received.Spec.Repository

assert.Equal(t, repo.Url, "git@github.com/renderextext/hello")

scheduler := received.Spec.Schedulers[0]

assert.Equal(t, scheduler.Name, "cron")
assert.Equal(t, scheduler.Branch, "master")
assert.Equal(t, scheduler.At, "* * * *")
assert.Equal(t, scheduler.PipelineFile, ".semaphore/cron.yml")
}