Files
OpenShell/sdk/go/openshell/v1/gateway/errors_test.go
Roland HussandDrew Newberry 8dc55e21ee feat(sdk/go): complete Go SDK with domain clients, auth, and hardening (#2702)
* feat(sdk/go): complete Go SDK with domain clients, auth, and hardening

Add the Go SDK implementation covering all gateway RPC services with
domain-typed clients, comprehensive OIDC authentication flows, fake
test doubles, and proto converters.

Domain clients: Sandbox, Provider, Exec, File, TCP, SSH, Policy,
Profile, Health, Service, Config, Workspace, Inference, Refresh.
Each client validates inputs, resolves sandboxes by name, and converts
between domain types and proto at the boundary.

Auth: OIDC authorization code (PKCE), device code (RFC 8628), and
client credentials (RFC 6749 Section 4.4) flows with gateway config
auto-resolution. Token refresh with singleflight deduplication and
exponential backoff. Edge tunnel proxy for gRPC-over-WebSocket.

Gateway: On-disk gateway discovery with user/system directory
precedence, lazy token loading, and auth mode mapping.

Testing: In-memory fake client with deep-copy isolation, watch
broadcasting with filtering, and workspace-scoped object stores.
Bufconn-based gRPC tests for all domain clients.

Ref: #2044

Signed-off-by: Roland Huß <rhuss@redhat.com>

* feat(sdk/go): add gateway client options for logger, timeout, and retry

Add WithLogger, WithTimeout, and WithRetryPolicy options to the gateway
package's NewClient function. These forward the corresponding Config
fields (Logger, Timeout, RetryPolicy) through to the underlying SDK
client, giving callers full control over observability, connection
timeouts, and retry behavior when constructing clients from on-disk
gateway configurations.

Also adds RetryPolicy type to types package and extends Config with the
three new fields.

* fix(mise): sync sccache lock entry

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

---------

Signed-off-by: Roland Huß <rhuss@redhat.com>
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
Co-authored-by: Drew Newberry <anewberry@nvidia.com>
2026-08-13 19:15:21 +00:00

89 lines
2.2 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package gateway
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// --- T011: Error type tests ---
func TestSentinelErrors_ErrorsIs(t *testing.T) {
sentinels := []struct {
name string
err error
}{
{"ErrGatewayNotFound", ErrGatewayNotFound},
{"ErrConfigParse", ErrConfigParse},
{"ErrTokenLoad", ErrTokenLoad},
{"ErrUnsupportedAuthMode", ErrUnsupportedAuthMode},
{"ErrInvalidGatewayName", ErrInvalidGatewayName},
{"ErrNoActiveGateway", ErrNoActiveGateway},
}
for _, tc := range sentinels {
t.Run(tc.name+"_direct", func(t *testing.T) {
assert.True(t, errors.Is(tc.err, tc.err),
"errors.Is should match sentinel directly")
})
t.Run(tc.name+"_wrapped", func(t *testing.T) {
wrapped := fmt.Errorf("context: %w", tc.err)
assert.True(t, errors.Is(wrapped, tc.err),
"errors.Is should match through fmt.Errorf wrapping")
})
t.Run(tc.name+"_double_wrapped", func(t *testing.T) {
inner := fmt.Errorf("inner: %w", tc.err)
outer := fmt.Errorf("outer: %w", inner)
assert.True(t, errors.Is(outer, tc.err),
"errors.Is should match through double wrapping")
})
}
}
func TestSentinelErrors_NotConfused(t *testing.T) {
// Verify that different sentinel errors are not equal.
pairs := []struct {
a, b error
}{
{ErrGatewayNotFound, ErrConfigParse},
{ErrConfigParse, ErrTokenLoad},
{ErrTokenLoad, ErrUnsupportedAuthMode},
{ErrUnsupportedAuthMode, ErrInvalidGatewayName},
{ErrInvalidGatewayName, ErrNoActiveGateway},
{ErrNoActiveGateway, ErrGatewayNotFound},
}
for _, tc := range pairs {
t.Run(tc.a.Error()+"_vs_"+tc.b.Error(), func(t *testing.T) {
assert.False(t, errors.Is(tc.a, tc.b),
"different sentinels must not match")
})
}
}
func TestSentinelErrors_HaveMessages(t *testing.T) {
sentinels := []error{
ErrGatewayNotFound,
ErrConfigParse,
ErrTokenLoad,
ErrUnsupportedAuthMode,
ErrInvalidGatewayName,
ErrNoActiveGateway,
}
for _, err := range sentinels {
t.Run(err.Error(), func(t *testing.T) {
msg := err.Error()
assert.NotEmpty(t, msg)
assert.Contains(t, msg, "gateway:")
})
}
}