telnyx-mock is a mock HTTP server that responds like the real Telnyx API. It can be used instead of Telnyx's test mode to make test suites integrating with Telnyx faster and less brittle. It's powered by the Telnyx OpenAPI specification, which is generated from within Telnyx's API.
telnyx-mock is able to generate an approximately correct API response for any endpoint, but the logic for doing so is still quite naive. It supports the following features:
name=foo
, a
messaging profile will be returned with "name": "foo"
.Limitations:
POST
of PATCH
calls won't be stored so
that the same information is available later.You can download a precompiled release for your platform (64-bit Windows, macOS, and Linux) and execute it. With no options, it will start an HTTP server on port 12111.
Get it from Homebrew:
brew install team-telnyx/telnyx-mock/telnyx-mock
# start a telnyx-mock service at login
brew services start telnyx-mock
# upgrade if you already have it
brew upgrade telnyx-mock
The Homebrew service listens on port 12111
for HTTP and 12112
for HTTPS and
HTTP/2.
# build
docker build . -t telnyx-mock
# run
docker run -p 12111-12112:12111-12112 telnyx-mock
The default Docker ENTRYPOINT
listens on port 12111
for HTTP and 12112
for HTTPS and HTTP/2.
If you have Go installed, you can build the basic binary with:
go get -u github.com/team-telnyx/telnyx-mock
With no arguments, telnyx-mock will listen with HTTP on its default port of
12111
and HTTPS on 12112
:
telnyx-mock
Ports can be specified explicitly with:
telnyx-mock -http-port 12111 -https-port 12112
(Leave either -http-port
or -https-port
out to activate telnyx-mock on only
one protocol.)
Have telnyx-mock select a port automatically by passing 0
:
telnyx-mock -http-port 0
It can also listen via Unix socket:
telnyx-mock -http-unix /tmp/telnyx-mock.sock -https-unix /tmp/telnyx-mock-secure.sock
After you've started telnyx-mock, you can try a sample request against it:
curl -i http://localhost:12111/v2/messaging_profiles -H "Authorization: Bearer
KEYSUPERSECRET"
Run the test suite:
go test ./...
The project uses go-bindata to bundle OpenAPI and fixture data into
bindata.go
so that it's automatically included with built executables.
You can retrieve the latest OpenAPI spec from https://api.telnyx.com/v2/mission_control_docs
Pretty format the json and overwrite the spec3.json
file in
openapi/openapi/
Rebuild it with:
# Make sure you have the go-bindata executable (it's not vendored into this
# repository).
go get -u github.com/jteeuwen/go-bindata/...
# Generates `bindata.go`, packing the spec as a string into a `.go`-file.
go generate
Release builds are generated with goreleaser. Make sure you have the software
and a GitHub token set at ~/.config/goreleaser/github_token
(brief docs here about it). Sorry about configuring it in the file; I (Nick) has issues where goreleaser seemed to ignore GITHUB_TOKEN
in the environment...
go get -u github.com/goreleaser/goreleaser
export GITHUB_TOKEN=...
Commit changes and tag HEAD
:
git pull origin --tags
git tag v0.1.1
git push origin --tags
Then run goreleaser and you're done! Check releases (it also pushes to the Homebrew tap).
goreleaser --rm-dist
The contributors and maintainers of Telnyx Mock would like to extend their deep gratitude to the authors of Stripe Mock, upon which this project is based. Thank you for developing such elegant, usable, and extensible code and for sharing it with the community.