Kai 44fd2a6871
Add Phoenix + Ecto example (#60)
* Boostrap Phoenix application from mix phx.new

* Add opentelemetry dependencies

* Setup opentelemetry for local env

* Setup Dockerfile, docker-compose and otel config

* Configure runtime config for exporter to export to otel collector in prod env

* Generate Posts HTML resources

* Add Release module to run migration in release

* Generate Users LiveView resource

* Add exporter configuration to export directly to external service

* Update README.md to include description and instructions

* Update README.md to include more details on exporting traces

* Fix otlp collector deprecated ports as suggested
2022-02-25 18:45:46 -07:00

62 lines
1.8 KiB
Elixir

defmodule Demo.BlogTest do
use Demo.DataCase
alias Demo.Blog
describe "posts" do
alias Demo.Blog.Post
import Demo.BlogFixtures
@invalid_attrs %{body: nil, title: nil}
test "list_posts/0 returns all posts" do
post = post_fixture()
assert Blog.list_posts() == [post]
end
test "get_post!/1 returns the post with given id" do
post = post_fixture()
assert Blog.get_post!(post.id) == post
end
test "create_post/1 with valid data creates a post" do
valid_attrs = %{body: "some body", title: "some title"}
assert {:ok, %Post{} = post} = Blog.create_post(valid_attrs)
assert post.body == "some body"
assert post.title == "some title"
end
test "create_post/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Blog.create_post(@invalid_attrs)
end
test "update_post/2 with valid data updates the post" do
post = post_fixture()
update_attrs = %{body: "some updated body", title: "some updated title"}
assert {:ok, %Post{} = post} = Blog.update_post(post, update_attrs)
assert post.body == "some updated body"
assert post.title == "some updated title"
end
test "update_post/2 with invalid data returns error changeset" do
post = post_fixture()
assert {:error, %Ecto.Changeset{}} = Blog.update_post(post, @invalid_attrs)
assert post == Blog.get_post!(post.id)
end
test "delete_post/1 deletes the post" do
post = post_fixture()
assert {:ok, %Post{}} = Blog.delete_post(post)
assert_raise Ecto.NoResultsError, fn -> Blog.get_post!(post.id) end
end
test "change_post/1 returns a post changeset" do
post = post_fixture()
assert %Ecto.Changeset{} = Blog.change_post(post)
end
end
end