store: add {Push,Pop}Compose methods and hide channel

Wrap the channel in Pop and Push methods, so it is not exposed to
the callers. PushCompose replaces the old AddCompose for consistency,
and PopCompose simply reads from the other end of the channel.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-05 17:51:30 +02:00 committed by Lars Karlitski
parent 3ff4f59fc7
commit 9cb140795e
6 changed files with 23 additions and 37 deletions

View file

@ -10,11 +10,9 @@ import (
"strings"
"testing"
"osbuild-composer/internal/job"
"osbuild-composer/internal/blueprint"
"osbuild-composer/internal/jobqueue"
"osbuild-composer/internal/pipeline"
"osbuild-composer/internal/store"
"osbuild-composer/internal/target"
"github.com/google/uuid"
)
@ -67,7 +65,7 @@ func testRoute(t *testing.T, api *jobqueue.API, method, path, body string, expec
}
func TestBasic(t *testing.T) {
expected_job := `{"id":"ffffffff-ffff-ffff-ffff-ffffffffffff","pipeline":{"assembler":{"name":"org.osbuild.tar","options":{"filename":"image.tar"}}},"targets":[{"name":"org.osbuild.local","options":{"location":"/tmp/ffffffff-ffff-ffff-ffff-ffffffffffff"}}]}`
expected_job := `{"id":"ffffffff-ffff-ffff-ffff-ffffffffffff","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
@ -90,19 +88,11 @@ func TestBasic(t *testing.T) {
//{"PATCH", "/job-queue/v1/jobs/ffffffff-ffff-ffff-ffff-ffffffffffff", `{"status":"FINISHED"}`, http.StatusNotAllowed, ``},
}
jobChannel := make(chan job.Job, 100)
api := jobqueue.New(nil, store.New(nil, nil, jobChannel), jobChannel)
store := store.New(nil, nil)
api := jobqueue.New(nil, store)
for _, c := range cases {
id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
p := &pipeline.Pipeline{}
p.SetAssembler(pipeline.NewTarAssembler(pipeline.NewTarAssemblerOptions("image.tar")))
jobChannel <- job.Job{
ComposeID: id,
Pipeline: p,
Targets: []*target.Target{
target.NewLocalTarget(target.NewLocalTargetOptions("/tmp/" + id.String())),
},
}
store.PushCompose(id, &blueprint.Blueprint{}, "tar")
testRoute(t, api, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedJSON)
}