d6b2f24c3f
One cross-client conformance pass; also closes first-cycle CLI-08. CLI-37: an MxStatusProxy entry is a failure iff `category != MX_STATUS_CATEGORY_OK`. The proto contract has always said so — `success` is the raw 16-bit COM member carried verbatim for diagnostics, not a boolean — but four clients branched on `success` alone and .NET required both, so the same gateway reply produced opposite verdicts per language. An absent entry stays success; a present entry with an UNSPECIFIED category is a failure, because the worker always maps a category and an unmapped one is not proven OK. CLI-38: a reply fails on HRESULT iff `hresult` is present and negative, so positive COM success codes such as S_FALSE (1) pass. .NET/Go/Java used `!= 0`, which errored on a parity-preserving S_FALSE that Python and Rust accepted. This makes the existing ClientLibrariesDesign.md claim true rather than rewriting the doc to describe the divergence. Four shared fixtures pin both rules cross-client, and each language suite also carries a table test for the two edges a fixture cannot express (absent entry, UNSPECIFIED category). A Java test fake that built a status with a bare `setSuccess(1)` and no category is fixed — under the category rule that reply was never a success.
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package mxgateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
pb "gitea.dohertylan.com/dohertj2/mxaccessgw/clients/go/internal/generated"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
func TestValueConversionFixtures(t *testing.T) {
|
|
data, err := os.ReadFile(filepath.Join("..", "..", "proto", "fixtures", "behavior", "values", "value-conversion-cases.json"))
|
|
if err != nil {
|
|
t.Fatalf("read fixture: %v", err)
|
|
}
|
|
|
|
var fixture struct {
|
|
Cases []struct {
|
|
ID string `json:"id"`
|
|
ExpectedKind string `json:"expectedKind"`
|
|
Value json.RawMessage `json:"value"`
|
|
} `json:"cases"`
|
|
}
|
|
if err := json.Unmarshal(data, &fixture); err != nil {
|
|
t.Fatalf("parse fixture manifest: %v", err)
|
|
}
|
|
|
|
for _, tc := range fixture.Cases {
|
|
t.Run(tc.ID, func(t *testing.T) {
|
|
var value pb.MxValue
|
|
if err := protojson.Unmarshal(tc.Value, &value); err != nil {
|
|
t.Fatalf("parse value: %v", err)
|
|
}
|
|
if _, err := NativeValue(&value); err != nil {
|
|
t.Fatalf("NativeValue() error = %v", err)
|
|
}
|
|
if got := value.ProtoReflect().WhichOneof(value.ProtoReflect().Descriptor().Oneofs().ByName("kind")).JSONName(); got != tc.ExpectedKind {
|
|
t.Fatalf("kind = %q, want %q", got, tc.ExpectedKind)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStatusConversionFixtures(t *testing.T) {
|
|
data, err := os.ReadFile(filepath.Join("..", "..", "proto", "fixtures", "behavior", "statuses", "status-conversion-cases.json"))
|
|
if err != nil {
|
|
t.Fatalf("read fixture: %v", err)
|
|
}
|
|
|
|
var fixture struct {
|
|
Cases []struct {
|
|
ID string `json:"id"`
|
|
Status json.RawMessage `json:"status"`
|
|
} `json:"cases"`
|
|
}
|
|
if err := json.Unmarshal(data, &fixture); err != nil {
|
|
t.Fatalf("parse fixture manifest: %v", err)
|
|
}
|
|
|
|
for _, tc := range fixture.Cases {
|
|
t.Run(tc.ID, func(t *testing.T) {
|
|
var status pb.MxStatusProxy
|
|
if err := protojson.Unmarshal(tc.Status, &status); err != nil {
|
|
t.Fatalf("parse status: %v", err)
|
|
}
|
|
want := status.GetCategory() == pb.MxStatusCategory_MX_STATUS_CATEGORY_OK
|
|
if got := StatusSucceeded(&status); got != want {
|
|
t.Fatalf("StatusSucceeded() = %v, want %v", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|