69 lines
2.5 KiB
Go
69 lines
2.5 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.ipao.vip/rogee/go-sip/contracts"
|
|
agentv1 "git.ipao.vip/rogee/go-sip/gen/agent/v1"
|
|
"git.ipao.vip/rogee/go-sip/internal/contract"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func TestActivationValidatesStaticCellArtifact(t *testing.T) {
|
|
raw, err := contracts.Read("examples/static-cell-artifact.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
server := NewServer(ServerOptions{
|
|
Now: func() time.Time { return time.Unix(100, 0) },
|
|
StaticArtifactRaw: raw,
|
|
StaticArtifactExpected: contract.StaticArtifactExpectation{
|
|
CellID: "cell-a",
|
|
Mode: "mock",
|
|
SourceRelease: "management-snapshot-1",
|
|
SourceDigest: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
ConfigSHA256: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
|
AllowedEgressPoolIDs: []string{"egress-mock"},
|
|
RequiredTrunkIDs: []string{"trunk-mock"},
|
|
},
|
|
})
|
|
meta := testMeta("activate-static", "", 0)
|
|
meta.CellId = "cell-a"
|
|
response, err := server.ActivateAgent(context.Background(), &agentv1.ActivateAgentRequest{
|
|
Meta: meta,
|
|
Binding: &agentv1.AgentBinding{AgentId: "agent-1", CellId: "cell-a", ExpectedBootId: "boot-1", DispatcherEpoch: "epoch-1", SessionGeneration: 1},
|
|
ActivationOperationId: "activate-static",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.State != agentv1.ActivationState_ACTIVATION_STATE_ACTIVE {
|
|
t.Fatalf("activation state=%s", response.State)
|
|
}
|
|
}
|
|
|
|
func TestActivationRejectsInvalidStaticCellArtifact(t *testing.T) {
|
|
raw, err := contracts.Read("examples/static-cell-artifact.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
server := NewServer(ServerOptions{
|
|
Now: func() time.Time { return time.Unix(100, 0) },
|
|
StaticArtifactRaw: raw,
|
|
StaticArtifactExpected: contract.StaticArtifactExpectation{CellID: "cell-b", Mode: "mock"},
|
|
})
|
|
meta := testMeta("activate-invalid-static", "", 0)
|
|
meta.CellId = "cell-a"
|
|
_, err = server.ActivateAgent(context.Background(), &agentv1.ActivateAgentRequest{
|
|
Meta: meta,
|
|
Binding: &agentv1.AgentBinding{AgentId: "agent-1", CellId: "cell-a", ExpectedBootId: "boot-1", DispatcherEpoch: "epoch-1", SessionGeneration: 1},
|
|
ActivationOperationId: "activate-invalid-static",
|
|
})
|
|
if err == nil || status.Code(err) != codes.FailedPrecondition {
|
|
t.Fatalf("invalid artifact error=%v code=%s", err, status.Code(err))
|
|
}
|
|
}
|