Files
wehub-resource-sync f99010fae1
Desktop Artifacts / Desktop Build (Linux) (push) Waiting to run
Desktop Artifacts / Desktop Build (Windows) (push) Waiting to run
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Waiting to run
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

81 lines
2.2 KiB
Go

package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.kenn.io/agentsview/internal/config"
)
// projectResolutionCase is a shared table-test row for the PG and DuckDB push
// project resolvers, which apply identical include/exclude precedence rules.
type projectResolutionCase[C any] struct {
name string
projects []string
exclude []string
cfg C
wantInclude []string
wantExclude []string
wantErr bool
}
// runProjectResolutionCases drives the shared project-resolution table against
// resolve, which adapts the configured projects/exclude lists and push config
// into the backend-specific resolver so PG and DuckDB stay in sync.
func runProjectResolutionCases[C any](
t *testing.T,
tests []projectResolutionCase[C],
resolve func(projects, exclude []string, cfg C) ([]string, []string, error),
) {
t.Helper()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
inc, exc, err := resolve(tt.projects, tt.exclude, tt.cfg)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.wantInclude, inc)
assert.Equal(t, tt.wantExclude, exc)
})
}
}
// pushRuntimeServer starts a daemon test server that serves a single push route
// at pushPath in addition to the standard daemon ping probe.
func pushRuntimeServer(
t *testing.T,
pushPath string,
pushHandler http.HandlerFunc,
) *httptest.Server {
t.Helper()
return daemonRouteTestServer(t, map[string]http.HandlerFunc{
pushPath: pushHandler,
})
}
// writeTestJSON sets the JSON content type and encodes value as the response
// body, failing the test on encode errors.
func writeTestJSON[T any](t *testing.T, w http.ResponseWriter, value T) {
t.Helper()
w.Header().Set("Content-Type", "application/json")
require.NoError(t, json.NewEncoder(w).Encode(value))
}
// newDaemonArchiveWriteBackendForTest builds a daemon-backed archive write
// backend that talks HTTP to url.
func newDaemonArchiveWriteBackendForTest(
appCfg config.Config,
url string,
) daemonArchiveWriteBackend {
return daemonArchiveWriteBackend{
appCfg: appCfg,
tr: transport{Mode: transportHTTP, URL: url},
}
}