refactor: tidy poller, web test helper and GoDoc line widths (#9)
This commit is contained in:
@@ -201,9 +201,15 @@ func newTestServer(t *testing.T) (*httptest.Server, *fakeStore, *fakeHub, *event
|
||||
return srv, store, hub, broker
|
||||
}
|
||||
|
||||
// newTestEnv starts the UI on fake storage. pollInterval is what the service
|
||||
// page shows as the polling interval; it defaults to zero.
|
||||
func newTestEnv(t *testing.T, pollInterval ...time.Duration) (*httptest.Server, *fakeStore, *fakeHub, *events.Broker, *fakeJobs) {
|
||||
// newTestEnv starts the UI on fake storage, with polling off.
|
||||
func newTestEnv(t *testing.T) (*httptest.Server, *fakeStore, *fakeHub, *events.Broker, *fakeJobs) {
|
||||
t.Helper()
|
||||
return newTestEnvPolling(t, 0)
|
||||
}
|
||||
|
||||
// newTestEnvPolling is newTestEnv with pollInterval as the polling interval
|
||||
// the service page shows.
|
||||
func newTestEnvPolling(t *testing.T, pollInterval time.Duration) (*httptest.Server, *fakeStore, *fakeHub, *events.Broker, *fakeJobs) {
|
||||
t.Helper()
|
||||
agentID := int64(2)
|
||||
store := &fakeStore{
|
||||
@@ -227,7 +233,7 @@ func newTestEnv(t *testing.T, pollInterval ...time.Duration) (*httptest.Server,
|
||||
jobs := &fakeJobs{}
|
||||
s, err := New(store, hub, jobs, broker, Config{
|
||||
AgentURL: "wss://10.0.0.5:8090/agent", MasterKey: "sha256:abc", AgentImage: "gitea.shcizo.se/shcizo/package-updater:latest",
|
||||
PollInterval: append(pollInterval, 0)[0],
|
||||
PollInterval: pollInterval,
|
||||
}, slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
require.NoError(t, err)
|
||||
mux := http.NewServeMux()
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<td><code title="{{.Ref}}">{{shortRef .Ref}}</code>{{if .Running}} <span class="badge">running</span>{{end}}{{if not .Tag}} <span class="muted">the service will follow no tag afterwards</span>{{end}}</td>
|
||||
<td>{{.Source}}</td>
|
||||
<td>{{.FirstSeenAt.Format "2006-01-02 15:04"}}</td>
|
||||
{{/* AutoBlocked is the same check that decides whether the service can be updated with an explicit ref, which is what a pick is. */}}
|
||||
<td>{{if not $.AutoBlocked}}
|
||||
<form method="post" action="/services/{{$.Service.ID}}/update">
|
||||
<input type="hidden" name="csrf_token" value="{{$.CSRF}}">
|
||||
|
||||
@@ -111,7 +111,7 @@ func TestServicePage_PollingRow(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
srv, store, _, _, _ := newTestEnv(t, 6*time.Hour)
|
||||
srv, store, _, _, _ := newTestEnvPolling(t, 6*time.Hour)
|
||||
tt.edit(&store.services[0])
|
||||
|
||||
_, body := get(t, srv, "/services/1")
|
||||
|
||||
Reference in New Issue
Block a user