f99010fae1
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
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.kenn.io/agentsview/internal/db"
|
|
)
|
|
|
|
func TestFetchHTTPProjects(t *testing.T) {
|
|
var gotAuth string
|
|
var gotQuery url.Values
|
|
ts := httptest.NewServer(http.HandlerFunc(func(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
assert.Equal(t, "/api/v1/projects", r.URL.Path)
|
|
gotAuth = r.Header.Get("Authorization")
|
|
gotQuery = r.URL.Query()
|
|
writeJSONResponse(w, `{
|
|
"projects": [
|
|
{"name": "alpha", "session_count": 3},
|
|
{"name": "beta", "session_count": 1}
|
|
]
|
|
}`)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
projects, err := fetchHTTPProjects(
|
|
context.Background(),
|
|
transport{Mode: transportHTTP, URL: ts.URL},
|
|
"secret-token",
|
|
true,
|
|
true,
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Bearer secret-token", gotAuth)
|
|
assert.Equal(t, "false", gotQuery.Get("include_one_shot"))
|
|
assert.Equal(t, "false", gotQuery.Get("include_automated"))
|
|
assert.Equal(t, []db.ProjectInfo{
|
|
{Name: "alpha", SessionCount: 3},
|
|
{Name: "beta", SessionCount: 1},
|
|
}, projects)
|
|
}
|
|
|
|
func TestFetchHTTPProjectsTimesOutStalledDaemon(t *testing.T) {
|
|
ts := httptest.NewServer(http.HandlerFunc(func(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
<-r.Context().Done()
|
|
}))
|
|
defer ts.Close()
|
|
|
|
oldClient := projectsHTTPClient
|
|
projectsHTTPClient = &http.Client{Timeout: 20 * time.Millisecond}
|
|
t.Cleanup(func() { projectsHTTPClient = oldClient })
|
|
|
|
_, err := fetchHTTPProjects(
|
|
context.Background(),
|
|
transport{Mode: transportHTTP, URL: ts.URL},
|
|
"",
|
|
false,
|
|
false,
|
|
)
|
|
|
|
require.Error(t, err)
|
|
}
|