feat: add Docker Swarm support (MODE=swarm) #4
@@ -86,6 +86,7 @@ func (h *Handlers) Update(w http.ResponseWriter, r *http.Request) {
|
|||||||
Project: res.Job.Project,
|
Project: res.Job.Project,
|
||||||
Service: res.Job.Service,
|
Service: res.Job.Service,
|
||||||
ComposeFile: composeFile,
|
ComposeFile: composeFile,
|
||||||
|
ServiceID: res.Job.ServiceID,
|
||||||
Status: string(res.Status),
|
Status: string(res.Status),
|
||||||
Error: res.Error,
|
Error: res.Error,
|
||||||
DurationMs: res.DurationMs,
|
DurationMs: res.DurationMs,
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/shcizo/package-updater/internal/api"
|
||||||
|
"github.com/shcizo/package-updater/internal/discovery"
|
||||||
|
"github.com/shcizo/package-updater/internal/updater"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type swarmResultFinder struct{ jobs []discovery.Job }
|
||||||
|
|
||||||
|
func (f *swarmResultFinder) FindJobs(_ context.Context, _ string) ([]discovery.Job, error) {
|
||||||
|
return f.jobs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type swarmResultSubmitter struct{ results []updater.Result }
|
||||||
|
|
||||||
|
func (s *swarmResultSubmitter) Submit(_ context.Context, _ []discovery.Job) []updater.Result {
|
||||||
|
return s.results
|
||||||
|
}
|
||||||
|
|
||||||
|
type swarmResultPinger struct{}
|
||||||
|
|
||||||
|
func (swarmResultPinger) Ping(_ context.Context) (types.Ping, error) { return types.Ping{}, nil }
|
||||||
|
|
||||||
|
func TestUpdate_SwarmJobPopulatesServiceID(t *testing.T) {
|
||||||
|
job := discovery.Job{Service: "myapp_web", ServiceID: "svc123", Image: "registry.example.com/myapp:v2"}
|
||||||
|
finder := &swarmResultFinder{jobs: []discovery.Job{job}}
|
||||||
|
submitter := &swarmResultSubmitter{results: []updater.Result{
|
||||||
|
{Job: job, Status: updater.StatusUpdated, DurationMs: 42},
|
||||||
|
}}
|
||||||
|
h := api.NewHandlers(finder, submitter, swarmResultPinger{}, "v", "c", "b", nil)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/update", strings.NewReader(`{"image":"registry.example.com/myapp"}`))
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
h.Update(rec, req)
|
||||||
|
|
||||||
|
require.Equal(t, http.StatusOK, rec.Code)
|
||||||
|
require.Contains(t, rec.Body.String(), `"service_id":"svc123"`)
|
||||||
|
require.Contains(t, rec.Body.String(), `"service":"myapp_web"`)
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ type ResultDTO struct {
|
|||||||
Project string `json:"project"`
|
Project string `json:"project"`
|
||||||
Service string `json:"service"`
|
Service string `json:"service"`
|
||||||
ComposeFile string `json:"compose_file"`
|
ComposeFile string `json:"compose_file"`
|
||||||
|
ServiceID string `json:"service_id,omitempty"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
DurationMs int64 `json:"duration_ms"`
|
DurationMs int64 `json:"duration_ms"`
|
||||||
|
|||||||
Reference in New Issue
Block a user