Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
feat: pokedex and slides (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc authored Oct 12, 2024
2 parents 79553ff + 9caf97d commit 5f8e89b
Show file tree
Hide file tree
Showing 25 changed files with 366 additions and 225 deletions.
13 changes: 1 addition & 12 deletions showcases/gin/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run:
test:
go test .

verify: test (up "-d") api-test lint
verify: test (up "-d") api-test
docker compose down

install-dep:
Expand All @@ -21,10 +21,6 @@ up c="": build
watch:
cargo watch -- just verify

# Run the static code analysis
lint:
golangci-lint run

# Build docker image for testing
build:
docker build -t {{image_name}} .
Expand All @@ -43,13 +39,6 @@ api-test *args: wait-for-api
api-test-not-implemented *args: wait-for-api
hurl api_tests/not_implemented/*.hurl {{hurl_opts}} {{args}}

# Install cargo dev-tools used by the `verify` recipe (requires rustup to be already installed)
install-dev-tools:
just install-linter

install-linter:
brew install golangci-lint
brew upgrade golangci-lint

install-hurl:
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl_4.1.0_amd64.deb
Expand Down
1 change: 1 addition & 0 deletions showcases/rocket/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion showcases/rocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jsonwebtoken = { version = "9.3", default-features = false }

reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-pki-types"] }
askama = {version = "0.12.1" }

rand = "0.8.5"

[profile.dev.build-override]
opt-level = 3
20 changes: 0 additions & 20 deletions showcases/rocket/Dockerfile

This file was deleted.

12 changes: 6 additions & 6 deletions showcases/rocket/api_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
docker build -t hurl-rocket:latest .
docker-compose down
docker-compose up -d
hurl api_tests/implemented/healthz.hurl --retry 60 --variables-file api_tests/hurl.env.test --test
hurl api_tests/implemented/*.hurl --variables-file api_tests/hurl.env.test --test
docker-compose down
lsof -t -i:8090 | xargs -r kill
cargo run & 2>&1
hurl api_tests/implemented/healthz.hurl --retry 4 --delay 1000 --variables-file api_tests/variables --test
hurl api_tests/implemented/*.hurl {{hurl_opts}} --variables-file api_tests/variables --test
lsof -t -i:8090 | xargs -r kill
echo "Verify done"
2 changes: 0 additions & 2 deletions showcases/rocket/api_tests/hurl.env.test~

This file was deleted.

36 changes: 36 additions & 0 deletions showcases/rocket/api_tests/hurl.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


hurl_opts := "--variables-file api_tests/variables --test"

# ---------------------------------------------------------------------------

# waits for healthy
wait-for-api:
hurl api_tests/implemented/healthz.hurl --retry 4 --delay 1000 {{hurl_opts}}

# run acceptance tests against the running test stack
api-test *args: wait-for-api
hurl api_tests/implemented/*.hurl {{hurl_opts}} {{args}}

# ---------------------------------------------------------------------------

run-release: shutdown
just run-q &

# will run the server without the logs
[no-exit-message]
@run-q *args:
cargo run {{args}} 2>&1

# shutdown whatever is running at the port
shutdown:
lsof -t -i:{{SERVER_PORT}} | xargs -r kill

# ---------------------------------------------------------------------------
# compose the api_test
api_tests:
#!/usr/bin/env bash
just shutdown
just run-release 2>&1
just api-test
just shutdown
34 changes: 32 additions & 2 deletions showcases/rocket/api_tests/implemented/pokemon_html.hurl
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
# try to get pokemons
# try to get pokemons html
GET {{target}}
HTTP 200

[Asserts]
xpath "string(/html/head/title)" contains "Pokédex"
xpath "string(/html/head/title)" contains "Pokédex"

# create a pokemon
POST {{target}}/api/pokemons
HTTP 200

# create another pokemon
POST {{target}}/api/pokemons
HTTP 200


# body should have 7 pokemon articles
GET {{target}}
HTTP 200

[Asserts]
xpath "count(/html/body//div/*)" == 7.0
xpath "/html/body//div/*" count == 7.0


# create another pokemon
POST {{target}}/api/pokemons
HTTP 200


# should now have 8 pokemons
GET {{target}}
HTTP 200

[Asserts]
xpath "/html/body//div/*" count == 8.0
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target=http://localhost:8002
target=http://localhost:8090
token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjEyMDkxMDkyOTAifQ.eyJhdWQiOlsibG9jYWwubXlfZG9tYWluLmNvbSJdLCJhenAiOiJkMTlYcDhEWEkxQVE4ZUNjeDdweHM5bkZiUTRUMHUwdCIsImVtYWlsIjoiam9obi5kb2VAb3B0cmF2aXMuY29tIiwiZXhwIjozMjUwMzY3NjQwMCwiaWF0IjowLCJpc3MiOiJodHRwczovL2F1dGgubXlfZG9tYWluLmNvbS8iLCJteV9vdGhlcl9zcGVjaWFsX2NsYWltIjoiaGVsbG8gd29ybGQiLCJuYW1lIjoiSm9obiIsInN1YiI6IjcwZTQ5M2Q5LTg0ZDAtNDliMS05YjYzLWJkNTVmOTVhOTI3ZSJ9.NQQFnHJlL7xiKP-6tk3gYrKpYPW8eVga_u5x6t3-l8U
1 change: 1 addition & 0 deletions showcases/rocket/assets/alpine-morph.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions showcases/rocket/assets/alpine.js

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions showcases/rocket/assets/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

.pokemon {
margin-bottom: 20px;
padding: 15px;
border-bottom: 1px solid #ddd;
}

.pokemon:last-child {
border-bottom: none;
}

.title{
margin-top: 8px;
}

.fixed-container{
height: 500px;
padding-bottom: 3px;
overflow-y: ;
}

:root {
--pico-font-family-sans-serif: Inter, system-ui, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, Helvetica, Arial, "Helvetica Neue", sans-serif, var(--pico-font-family-emoji);
--pico-font-size: 87.5%;
/* Original: 100% */
--pico-line-height: 1.25;
/* Original: 1.5 */
--pico-form-element-spacing-vertical: 0.5rem;
/* Original: 1rem */
--pico-form-element-spacing-horizontal: 1.0rem;
/* Original: 1.25rem */
--pico-border-radius: 0.375rem;
/* Original: 0.25rem */
}

@media (min-width: 576px) {
:root {
--pico-font-size: 87.5%;
/* Original: 106.25% */
}
}

@media (min-width: 768px) {
:root {
--pico-font-size: 87.5%;
/* Original: 112.5% */
}
}

@media (min-width: 1024px) {
:root {
--pico-font-size: 87.5%;
/* Original: 118.75% */
}
}

@media (min-width: 1280px) {
:root {
--pico-font-size: 87.5%;
/* Original: 125% */
}
}

@media (min-width: 1536px) {
:root {
--pico-font-size: 87.5%;
/* Original: 131.25% */
}
}

h1,
h2,
h3,
h4,
h5,
h6 {
--pico-font-weight: 600;
/* Original: 700 */
}

article {
border: 1px solid var(--pico-muted-border-color);
/* Original doesn't have a border */
border-radius: calc(var(--pico-border-radius) * 2);
/* Original: var(--pico-border-radius) */
}

article>footer {
border-radius: calc(var(--pico-border-radius) * 2);
/* Original: var(--pico-border-radius) */
}
16 changes: 16 additions & 0 deletions showcases/rocket/assets/htmx-alpine-morph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
htmx.defineExtension('alpine-morph', {
isInlineSwap: function(swapStyle) {
return swapStyle === 'morph'
},
handleSwap: function(swapStyle, target, fragment) {
if (swapStyle === 'morph') {
if (fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
Alpine.morph(target, fragment.firstElementChild)
return [target]
} else {
Alpine.morph(target, fragment.outerHTML)
return [target]
}
}
}
})
1 change: 1 addition & 0 deletions showcases/rocket/assets/htmx.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions showcases/rocket/assets/pico.min.css

Large diffs are not rendered by default.

49 changes: 15 additions & 34 deletions showcases/rocket/justfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,50 @@
set dotenv-load
import 'api_tests/hurl.just'

image_name := "hurl-rocket:latest"
hurl_opts := "--variables-file api_tests/hurl.env.test --test"


export ROCKET_PORT := "8002"
export ROCKET_PORT := "8090"
export SERVER_PORT := "8090"
export AUTH_HS256_SECRET := "CTRKew35ltwdWhGv9WF10lJ06oYBZKzACYhANx7QXPZpvBvCNZbq161xHg2rKhcp"
export AUTH_JWT_AUD := "local.my_domain.com"

@_list:
just --list --unsorted

# Perform all verifications (compile, test, lint, etc.)
verify: test api_tests lint
docker compose down
@verify: test lint api_tests
echo ------------ verify done! ------------

# Run the service locally (from sources)
run:
cargo run
@sh:
./api_tests.sh

api_tests: build (up "-d") api-test
docker compose down

up c="": build
docker compose down
docker compose up {{c}}
run *args:
cargo run -q -- {{args}}

# Watch the source files and run `just verify` when source changes
watch:
cargo watch -- just verify
cargo watch -- just run

# Run the tests
# Run tests
test:
cargo hack test --feature-powerset --locked
cargo deny check licenses
cargo test

# Run the static code analysis
lint:
cargo fmt --all -- --check
cargo hack clippy --feature-powerset --all-targets --workspace --locked
cargo deny check
cargo fmt --all -- --check
cargo clippy

# Clean up compilation output
clean:
rm -rf target
rm -rf node_modules


# Build docker image for testing
build:
docker build -t {{image_name}} .

wait-for-api:
hurl api_tests/implemented/healthz.hurl --retry 60 {{hurl_opts}}

pre-api-test:
hurl api/pre_test/*.hurl {{hurl_opts}}

# run acceptance tests against the running test stack
api-test *args: wait-for-api
hurl api_tests/implemented/*.hurl {{hurl_opts}} {{args}}

# run all acceptance tests against the running test stack, including for non-implemented api
api-test-not-implemented *args: wait-for-api
hurl api_tests/not_implemented/*.hurl {{hurl_opts}} {{args}}

# Install cargo dev-tools used by the `verify` recipe (requires rustup to be already installed)
install-dev-tools:
Expand All @@ -81,7 +63,6 @@ install-hurl:
@replace-token:
cd token_creation && just replace


prune:
cargo machete
cargo features prune
5 changes: 5 additions & 0 deletions showcases/rocket/src/assets/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use rocket::fs::{relative, FileServer, Options};

pub fn assets() -> FileServer {
FileServer::new(relative!("/assets"), Options::default())
}
Loading

0 comments on commit 5f8e89b

Please sign in to comment.