Skip to content

Commit d47176e

Browse files
test: mock-support-server
1 parent 54b6f26 commit d47176e

20 files changed

+2514
-0
lines changed

mock-support-server/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM golang:1.24-alpine3.22 AS build
2+
WORKDIR /src/mock-support-server
3+
4+
# Copy module files and download dependencies (cached)
5+
COPY mock-support-server/go.mod ./go.mod
6+
COPY mock-support-server/go.sum ./go.sum
7+
RUN --mount=type=cache,target=/go/pkg/mod \
8+
go mod download
9+
10+
# Copy sources (protos are already generated and checked in)
11+
COPY mock-support-server/main.go ./main.go
12+
COPY mock-support-server/genproto ./genproto
13+
14+
# Build statically linked binary
15+
RUN --mount=type=cache,target=/go/pkg/mod \
16+
--mount=type=cache,target=/root/.cache/go-build \
17+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/mock-support-server .
18+
19+
FROM alpine:3.22
20+
COPY --from=build /out/mock-support-server /mock-support-server
21+
COPY data/account_id /data/account_id
22+
COPY data/resolver_state_current.pb /data/resolver_state_current.pb
23+
# Single unified port for HTTP+h2c (REST+gRPC)
24+
ENV PORT=8081
25+
EXPOSE 8081
26+
ENTRYPOINT ["/mock-support-server"]
27+
28+

mock-support-server/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PROTO_SRC := $(shell find proto/mock -type f -name '*.proto' | sort)
2+
GEN_DIR := genproto
3+
GOBIN := $(shell go env GOPATH)/bin
4+
5+
.PHONY: gen run-iam clean
6+
7+
gen: $(PROTO_SRC)
8+
@mkdir -p $(GEN_DIR)
9+
PATH="$(GOBIN):$$PATH" protoc -I proto \
10+
--go_out=paths=source_relative:$(GEN_DIR) \
11+
--go-grpc_out=paths=source_relative:$(GEN_DIR) \
12+
--grpc-gateway_out=paths=source_relative,allow_delete_body=true:$(GEN_DIR) \
13+
$(PROTO_SRC)
14+
15+
run-iam: gen
16+
go run -tags iamonly .
17+
18+
clean:
19+
rm -rf $(GEN_DIR)
20+
21+

mock-support-server/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Confidence Mock Support Server (Go)
2+
3+
Single-binary mock of Confidence HTTP and gRPC backends for provider benchmarks and tests.
4+
5+
## Features
6+
- HTTP endpoints:
7+
- POST /v1/oauth/token → { accessToken, expiresIn }
8+
- GET /v1/resolverState:resolverStateUri → { signedUri, account }
9+
- GET /state.pb → serves resolver state bytes with ETag + 304
10+
- POST /v1/flags:resolve → ResolveFlagsResponse (JSON)
11+
- POST /v1/flagLogs:write → 200 OK (accepts application/x-protobuf)
12+
- GET /healthz → 200 OK
13+
- gRPC endpoints:
14+
- confidence.flags.admin.v1.ResolverStateService (ResolverStateUri, FullResolverState)
15+
- confidence.flags.resolver.v1.InternalFlagLoggerService (WriteFlagLogs, WriteFlagAssigned)
16+
- One process, one container. No sidecars needed.
17+
18+
Note: Public gRPC stubs for FlagResolverService are not generated here, so flags resolve is provided over HTTP only.
19+
20+
## Configuration (env)
21+
- PORT_HTTP (default 8081)
22+
- PORT_GRPC (default 9091)
23+
- ACCOUNT_ID (default read from data/account_id)
24+
- RESOLVER_STATE_PB (default data/resolver_state_current.pb if present)
25+
- STATIC_TOKEN (default "mock-token")
26+
- TOKEN_EXPIRES_IN (default 3600)
27+
- FLAGS_RESPONSE_MODE (static|echo|file) [currently static]
28+
- STATIC_FLAG_VARIANT (default flags/foo/variants/default)
29+
- STATIC_FLAG_VALUE (default {"value":true})
30+
31+
## Build and run
32+
33+
Docker build:
34+
```bash
35+
docker build -f mock-support-server/Dockerfile -t cnfd-mock .
36+
```
37+
38+
Run:
39+
```bash
40+
docker run --rm -p 8081:8081 -p 9091:9091 \
41+
-e ACCOUNT_ID=test-account \
42+
-e RESOLVER_STATE_PB=/data/resolver_state_current.pb \
43+
cnfd-mock
44+
```
45+
46+
## Using with JS benchmark
47+
- Override provider fetch to route Confidence hosts to http://mock:8081
48+
- Or run the benchmark container in a compose network and target `mock:8081`
49+
50+
## Notes
51+
- Extend as needed to support additional endpoints or behaviors.
52+
- grpc-gateway can be added later if you want REST<->gRPC parity on one port.
53+
54+

mock-support-server/genproto/mock/flags_admin.pb.go

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)