Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ tasks:
silent: true
cmds:
# We have to use ldflags to avoid the LC_DYSYMTAB linker warning.
- go test -ldflags=-extldflags=-Wl,-w -race -json ./... | gotestfmt -hide "all"
- go test -count 1 -ldflags=-extldflags=-Wl,-w -race -json ./... | gotestfmt -hide "all"

test-coverage:
desc: Run registry API tests with coverage
Expand All @@ -186,7 +186,7 @@ tasks:
silent: true
cmds:
# We have to use ldflags to avoid the LC_DYSYMTAB linker warning.
- go test -ldflags=-extldflags=-Wl,-w -race -json -coverprofile=coverage.out ./... | gotestfmt -hide "all"
- go test -count 1 -ldflags=-extldflags=-Wl,-w -race -json -coverprofile=coverage.out ./... | gotestfmt -hide "all"
- go tool cover -func=coverage.out
- echo "Generating HTML coverage report in coverage.html"
- go tool cover -html=coverage.out -o coverage.html
Expand Down
2 changes: 1 addition & 1 deletion database/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestMigrations(t *testing.T) {
t.Parallel()

ctx := context.Background()
db, cleanupFunc := SetupTestDBContaienr(t, ctx)
db, cleanupFunc := SetupTestDBContainer(t, ctx)
t.Cleanup(cleanupFunc)

connString := db.Config().ConnString()
Expand Down
18 changes: 15 additions & 3 deletions database/queries/registry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ SELECT id,
updated_at
FROM registry
WHERE (sqlc.narg(next)::timestamp with time zone IS NULL OR created_at > sqlc.narg(next))
OR (sqlc.narg(prev)::timestamp with time zone IS NULL AND created_at < sqlc.narg(prev))
AND (sqlc.narg(prev)::timestamp with time zone IS NULL OR created_at < sqlc.narg(prev))
ORDER BY
-- next page sorting
CASE WHEN sqlc.narg(next)::timestamp with time zone IS NULL THEN created_at END ASC,
CASE WHEN sqlc.narg(next)::timestamp with time zone IS NULL THEN name END ASC,
-- previous page sorting
CASE WHEN sqlc.narg(prev)::timestamp with time zone IS NULL THEN created_at END DESC
CASE WHEN sqlc.narg(prev)::timestamp with time zone IS NULL THEN created_at END DESC,
CASE WHEN sqlc.narg(prev)::timestamp with time zone IS NULL THEN name END DESC
LIMIT sqlc.arg(size)::bigint;

-- name: GetRegistry :one
Expand All @@ -24,4 +26,14 @@ SELECT id,
WHERE id = sqlc.arg(id);

-- name: InsertRegistry :one
INSERT INTO registry (name, reg_type) VALUES ($1, $2) RETURNING id;
INSERT INTO registry (
name,
reg_type,
created_at,
updated_at
) VALUES (
sqlc.arg(name),
sqlc.arg(reg_type),
sqlc.arg(created_at),
sqlc.arg(updated_at)
) RETURNING id;
10 changes: 5 additions & 5 deletions database/queries/servers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SELECT r.reg_type as registry_type,
JOIN registry r ON s.reg_id = r.id
LEFT JOIN latest_server_version l ON s.id = l.latest_server_id
WHERE (sqlc.narg(next)::timestamp with time zone IS NULL OR s.created_at > sqlc.narg(next))
OR (sqlc.narg(prev)::timestamp with time zone IS NULL AND s.created_at < sqlc.narg(prev))
AND (sqlc.narg(prev)::timestamp with time zone IS NULL OR s.created_at < sqlc.narg(prev))
ORDER BY
-- next page sorting
CASE WHEN sqlc.narg(next)::timestamp with time zone IS NULL THEN r.reg_type END ASC,
Expand Down Expand Up @@ -79,7 +79,7 @@ SELECT s.id,
FROM mcp_server s
WHERE s.name = sqlc.arg(name)
AND ((sqlc.narg(next)::timestamp with time zone IS NULL OR s.created_at > sqlc.narg(next))
OR (sqlc.narg(prev)::timestamp with time zone IS NULL AND s.created_at < sqlc.narg(prev)))
AND (sqlc.narg(prev)::timestamp with time zone IS NULL OR s.created_at < sqlc.narg(prev)))
ORDER BY
CASE WHEN sqlc.narg(next)::timestamp with time zone IS NULL THEN s.created_at END ASC,
CASE WHEN sqlc.narg(next)::timestamp with time zone IS NULL THEN s.version END DESC -- acts as tie breaker
Expand All @@ -105,8 +105,8 @@ INSERT INTO mcp_server (
sqlc.arg(name),
sqlc.arg(version),
sqlc.arg(reg_id),
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
sqlc.arg(created_at),
sqlc.arg(updated_at),
sqlc.narg(description),
sqlc.narg(title),
sqlc.narg(website),
Expand All @@ -118,7 +118,7 @@ INSERT INTO mcp_server (
sqlc.narg(repository_type)
) ON CONFLICT (reg_id, name, version)
DO UPDATE SET
updated_at = CURRENT_TIMESTAMP,
updated_at = sqlc.arg(updated_at),
description = sqlc.narg(description),
title = sqlc.narg(title),
website = sqlc.narg(website),
Expand Down
2 changes: 1 addition & 1 deletion database/queries/sync.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ INSERT INTO registry_sync (
sqlc.arg(reg_id),
sqlc.arg(sync_status),
sqlc.narg(error_msg),
CURRENT_TIMESTAMP
sqlc.arg(started_at)
) RETURNING id;

-- name: UpdateRegistrySync :exec
Expand Down
6 changes: 3 additions & 3 deletions database/testcontainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var (
dbPass = "testpass"
)

// SetupTestDBContaienr creates a Postgres container using testcontainers and returns a connection to the database
// SetupTestDBContainer creates a Postgres container using testcontainers and returns a connection to the database
//
//nolint:revive
func SetupTestDBContaienr(t *testing.T, ctx context.Context) (*pgx.Conn, func()) {
func SetupTestDBContainer(t *testing.T, ctx context.Context) (*pgx.Conn, func()) {
t.Helper()

// Start Postgres container
Expand Down Expand Up @@ -58,7 +58,7 @@ func SetupTestDB(t *testing.T) (*pgx.Conn, func()) {
t.Helper()

ctx := context.Background()
db, containerCleanupFunc := SetupTestDBContaienr(t, ctx)
db, containerCleanupFunc := SetupTestDBContainer(t, ctx)

// Apply migrations
err := MigrateUp(ctx, db)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/stacklok/toolhive-registry-server
go 1.25.3

require (
github.com/aws/smithy-go v1.13.3
github.com/go-chi/chi/v5 v5.2.3
github.com/go-git/go-billy/v5 v5.6.2
github.com/go-git/go-git/v5 v5.16.3
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/smithy-go v1.13.3 h1:l7LYxGuzK6/K+NzJ2mC+VvLUbae0sL3bXU//04MkmnA=
github.com/aws/smithy-go v1.13.3/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
Expand Down Expand Up @@ -158,6 +160,7 @@ github.com/golang-migrate/migrate/v4 v4.19.0/go.mod h1:9dyEcu+hO+G9hPSw8AIg50yg6
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -188,6 +191,8 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE=
Expand Down Expand Up @@ -453,6 +458,7 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
105 changes: 53 additions & 52 deletions internal/db/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions internal/db/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading