-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathinternalbindings_test.go
More file actions
63 lines (55 loc) · 2.45 KB
/
internalbindings_test.go
File metadata and controls
63 lines (55 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Tests covering the publicly exposed Nexus caller-side bindings added so
// that non-Go SDKs (e.g. roadrunner-temporal proxying for PHP) can build
// `ExecuteNexusOperationParams` from outside the `internal` package.
//
// The constructor is the only way for an external caller to populate the
// struct — its fields stay unexported on purpose. These tests document and
// guard that contract.
package internalbindings
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
commonpb "go.temporal.io/api/common/v1"
)
func TestNewNexusClient_ExposesEndpointAndService(t *testing.T) {
c := NewNexusClient("ep-1", "svc-1")
require.NotNil(t, c, "client constructor must return a non-nil NexusClient")
// NexusClient is an interface from go.temporal.io/sdk/internal — it
// exposes Endpoint() and Service() readers. We assert through the
// re-exported alias so the test breaks loudly if the interface shape
// changes upstream and the alias drifts.
assert.Equal(t, "ep-1", c.Endpoint())
assert.Equal(t, "svc-1", c.Service())
}
func TestNewExecuteNexusOperationParams_RoundtripsAllFields(t *testing.T) {
// The struct's fields are unexported, so the only contract surface
// is "what you put in is what dispatchers see when they call
// WorkflowEnvironment.ExecuteNexusOperation". We can't read fields
// directly, but we can verify the constructor accepts the documented
// inputs without panicking and returns a value of the public type.
client := NewNexusClient("ep-2", "svc-2")
payload := &commonpb.Payload{Data: []byte("hello")}
options := NexusOperationOptions{}
headers := map[string]string{"Nexus-Operation-Token": "tok-x"}
params := NewExecuteNexusOperationParams(client, "op-1", payload, options, headers)
// The exported type alias must match the type returned by the
// constructor — protects against accidental drift between the
// `type ExecuteNexusOperationParams = internal....` line and the
// `func NewExecuteNexusOperationParams ... ExecuteNexusOperationParams`
// line.
var _ ExecuteNexusOperationParams = params
}
func TestNewExecuteNexusOperationParams_AcceptsNilHeader(t *testing.T) {
// Headers map is optional — Java callers that don't surface a Nexus
// header just pass nil. Ensure nil doesn't panic on construction.
require.NotPanics(t, func() {
NewExecuteNexusOperationParams(
NewNexusClient("ep", "svc"),
"op",
nil, // input
NexusOperationOptions{},
nil, // header
)
})
}