Add runnable smoke-test clients for each SDK
CI / js (push) Successful in 18s
CI / go (push) Successful in 36s
CI / rust (push) Successful in 2m3s

Each package gets a small example program that exercises the real
client: with no ORIGIN_SERVICE_KEY set it runs against a local mock
check-in server, otherwise it checks in against ORIGIN_URL/Origin's
public endpoint. Wired into CI (mock mode) as a regression check, and
documented per README.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 15:38:37 +02:00
co-authored by Claude Sonnet 5
parent 2590e404f5
commit ac3c0f149c
9 changed files with 331 additions and 2 deletions
+98
View File
@@ -0,0 +1,98 @@
// Command testclient is a runnable smoke test for the Go originclient SDK.
//
// Without ORIGIN_SERVICE_KEY set, it spins up a local mock check-in server
// and exercises the client against it — no network, no credentials needed.
// With ORIGIN_SERVICE_KEY set, it performs a real check-in against
// ORIGIN_URL (or Origin's public endpoint) so the SDK can be smoke-tested
// end-to-end against a live server.
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"net/http/httptest"
"os"
"os/signal"
"strconv"
"syscall"
originclient "git.warky.dev/wdevs/origin_client/go"
)
func main() {
watch := flag.Bool("watch", false, "run continuously via Run() instead of a single check-in")
flag.Parse()
cfg := originclient.Config{
URL: os.Getenv("ORIGIN_URL"),
ServiceKey: os.Getenv("ORIGIN_SERVICE_KEY"),
Type: envOr("ORIGIN_TYPE", "icy2-testclient"),
Version: envOr("ORIGIN_VERSION", "0.0.0-test"),
Name: envOr("ORIGIN_NAME", "icy2-testclient-local"),
Site: os.Getenv("ORIGIN_SITE"),
Environment: os.Getenv("ORIGIN_ENVIRONMENT"),
Logger: originclient.LoggerFunc(func(msg string, err error) { log.Printf("[warn] %s: %v", msg, err) }),
}
if cfg.ServiceKey == "" {
log.Println("ORIGIN_SERVICE_KEY not set — using a local mock check-in server")
server := httptest.NewServer(http.HandlerFunc(mockHandler))
defer server.Close()
cfg.URL = server.URL
cfg.ServiceKey = "test-key"
cfg.InstallID = "test-install-id"
}
if h := os.Getenv("ORIGIN_INTERVAL_HOURS"); h != "" {
if n, err := strconv.Atoi(h); err == nil {
cfg.IntervalHours = n
}
}
client, err := originclient.New(cfg)
if err != nil {
log.Fatalf("originclient.New: %v", err)
}
if *watch {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
log.Println("watching — Ctrl-C to stop")
client.Run(ctx)
return
}
resp, err := client.CheckinOnce(context.Background())
if err != nil {
log.Fatalf("checkin failed: %v", err)
}
out, _ := json.MarshalIndent(resp, "", " ")
fmt.Println(string(out))
}
func mockHandler(w http.ResponseWriter, r *http.Request) {
var payload originclient.Payload
_ = json.NewDecoder(r.Body).Decode(&payload)
log.Printf("mock server received check-in: type=%s name=%s install_id=%s key=%s",
payload.Type, payload.Name, payload.UniqueInstallID, r.Header.Get("X-Origin-Service-Key"))
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(originclient.Response{
Success: true,
ServiceInstanceID: 1,
UniqueInstallID: payload.UniqueInstallID,
Status: "provisioning",
PingedAt: "2026-08-01T00:00:00Z",
})
}
func envOr(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}