target: add constructor

We only support local target for now, but this avoids having to
open code it.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-09-27 15:54:13 +02:00
parent f880581a14
commit 5df6874b94
5 changed files with 20 additions and 19 deletions

View file

@ -10,7 +10,7 @@ import (
type Job struct {
ComposeID uuid.UUID
Pipeline pipeline.Pipeline
Targets []target.Target
Targets []*target.Target
}
type Status struct {

View file

@ -84,7 +84,7 @@ func (api *API) addJobHandler(writer http.ResponseWriter, request *http.Request,
}
type replyBody struct {
Pipeline pipeline.Pipeline `json:"pipeline"`
Targets []target.Target `json:"targets"`
Targets []*target.Target `json:"targets"`
}
contentType := request.Header["Content-Type"]

View file

@ -66,7 +66,7 @@ func testRoute(t *testing.T, api *jobqueue.API, method, path, body string, expec
}
func TestBasic(t *testing.T) {
expected_job := `{"pipeline":{"assembler":{"name":"org.osbuild.tar","options":{"filename":"image.tar"}}},"targets":[{"name":"org.osbuild.local","options":{"location":"/var/lib/osbuild-composer/ffffffff-ffff-ffff-ffff-ffffffffffff"}}]}`
expected_job := `{"pipeline":{"assembler":{"name":"org.osbuild.tar","options":{"filename":"image.tar"}}},"targets":[{"name":"org.osbuild.local","options":{"location":"/var/lib/osbuild-composer/outputs/ffffffff-ffff-ffff-ffff-ffffffffffff"}}]}`
var cases = []struct {
Method string
Path string
@ -104,12 +104,7 @@ func TestBasic(t *testing.T) {
},
},
},
Targets: []target.Target{{
Name: "org.osbuild.local",
Options: target.LocalOptions{
Location: "/var/lib/osbuild-composer/ffffffff-ffff-ffff-ffff-ffffffffffff",
}},
},
Targets: []*target.Target{target.New(id)},
}
testRoute(t, api, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedJSON)

View file

@ -1,10 +1,21 @@
package target
import "github.com/google/uuid"
type Target struct {
Name string `json:"name"`
Options LocalOptions `json:"options"`
Name string `json:"name"`
Options Options `json:"options"`
}
type LocalOptions struct {
type Options struct {
Location string `json:"location"`
}
func New(ComposeID uuid.UUID) *Target {
return &Target{
Name: "org.osbuild.local",
Options: Options{
Location: "/var/lib/osbuild-composer/outputs/" + ComposeID.String(),
},
}
}

View file

@ -39,7 +39,7 @@ type blueprintPackage struct {
type compose struct {
Status string `json:"status"`
Pipeline pipeline.Pipeline `json:"pipeline"`
Targets []target.Target `json:"targets"`
Targets []*target.Target `json:"targets"`
}
func newStore(initialState []byte, stateChannel chan<- []byte, pendingJobs chan<- job.Job, jobUpdates <-chan job.Status) *store {
@ -190,12 +190,7 @@ func (s *store) deleteBlueprintFromWorkspace(name string) {
func (s *store) addCompose(composeID uuid.UUID, bp blueprint, composeType string) {
pipeline := bp.translateToPipeline(composeType)
targets := []target.Target{{
Name: "org.osbuild.local",
Options: target.LocalOptions{
Location: "/var/lib/osbuild-composer/" + composeID.String(),
},
}}
targets := []*target.Target{target.New(composeID)}
s.change(func() {
s.Composes[composeID] = compose{"pending", pipeline, targets}
})