fluid-core/conformance/handover_test.go

52 lines
1.4 KiB
Go
Raw Normal View History

package conformance
import (
"os"
"testing"
"github.com/tegwick/fluid-core/internal/validate"
)
// TestTelegramHandoverContractCompiles checks that the contract shipped in the
// fluid-telegram handover is one this gateway can actually enforce.
//
// A handover that shipped a contract the framework cannot parse would fail at
// the first publication, after the bot and channel had already been created.
// The check is skipped when the sibling repository is absent, so CI in a bare
// checkout still passes.
func TestTelegramHandoverContractCompiles(t *testing.T) {
const path = "../../fluid-telegram/contracts/r1.openapi.yaml"
raw, err := os.ReadFile(path)
if err != nil {
t.Skipf("fluid-telegram not checked out beside fluid-core: %v", err)
}
c, err := validate.ParseOpenAPI(raw)
if err != nil {
t.Fatalf("the handover contract does not compile: %v", err)
}
ops := c.Operations()
want := map[string]bool{
"GET /v1/channel-posts": false,
"POST /v1/channel-posts": false,
"GET /v1/channel-posts/{post_id}": false,
}
for _, op := range ops {
if _, tracked := want[op]; tracked {
want[op] = true
}
}
for op, found := range want {
if !found {
t.Errorf("the contract does not declare %s; it has %v", op, ops)
}
}
// The interface's complexity budget allows a maximum of 8 operations.
if len(ops) > 8 {
t.Errorf("the contract declares %d operations, over the intent's budget of 8", len(ops))
}
}