diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0ce56c9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: ci + +on: + pull_request: + paths: + - 'learn-cicd/**' + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./learn-cicd + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.27.1" + + - name: Run unit tests + run: go test ./... -cover \ No newline at end of file diff --git a/README.md b/README.md index ce90241..f238ae1 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,19 @@ A collection of projects completed as part of my coursework on [Boot.dev](https: ## Projects -| Project | Description | -| --- | --- | -| [`chirpy`](./chirpy) | HTTP web server built from scratch in Go, including routing, JSON handling, and a REST API backed by a database. | -| [`pokedexcli`](./pokedexcli) | A CLI Pokedex in Go that consumes the PokeAPI REST API, with caching and a REPL-style interface. | -| [`gator`](./gator) | RSS feed aggregator CLI in Go with persistent storage (PostgreSQL) and scheduled feed fetching. | -| [`http-from-tcp`](./http-from-tcp) | Implements an HTTP server from raw TCP sockets in Go, without using the standard `net/http` package, to understand the protocol at a low level. | -| [`learn-pub-sub`](./learn-pub-sub) | Pub/sub messaging system in Go using RabbitMQ, built around a multiplayer game simulation. | -| [`kubernetes`](./kubernetes) | Deploying and orchestrating an application with Kubernetes. | -| [`static-site-generator`](./static-site-generator) | A static site generator written in Python that converts Markdown files into HTML pages. | -| [`asteroids`](./asteroids) | A recreation of the classic Asteroids arcade game in Python using Pygame. | -| [`bookbot`](./bookbot) | A Python CLI tool that analyzes text files and reports word counts and character frequency statistics. | -| [`ai-agent`](./ai-agent) | A toy AI coding agent in Python that uses an LLM (via function calling) to read, write, and execute files in a sandboxed directory. | +| Project | CI | Description | +| --- | --- | --- | +| [`chirpy`](./chirpy) | | HTTP web server built from scratch in Go, including routing, JSON handling, and a REST API backed by a database. | +| [`pokedexcli`](./pokedexcli) | | A CLI Pokedex in Go that consumes the PokeAPI REST API, with caching and a REPL-style interface. | +| [`gator`](./gator) | | RSS feed aggregator CLI in Go with persistent storage (PostgreSQL) and scheduled feed fetching. | +| [`http-from-tcp`](./http-from-tcp) | | Implements an HTTP server from raw TCP sockets in Go, without using the standard `net/http` package, to understand the protocol at a low level. | +| [`learn-pub-sub`](./learn-pub-sub) | | Pub/sub messaging system in Go using RabbitMQ, built around a multiplayer game simulation. | +| [`kubernetes`](./kubernetes) | | Deploying and orchestrating an application with Kubernetes. | +| [`static-site-generator`](./static-site-generator) | | A static site generator written in Python that converts Markdown files into HTML pages. | +| [`asteroids`](./asteroids) | | A recreation of the classic Asteroids arcade game in Python using Pygame. | +| [`bookbot`](./bookbot) | | A Python CLI tool that analyzes text files and reports word counts and character frequency statistics. | +| [`ai-agent`](./ai-agent) | | A toy AI coding agent in Python that uses an LLM (via function calling) to read, write, and execute files in a sandboxed directory. | +| [`learn-cicd`](./learn-cicd) | ![learn-cicd](https://github.com/lennago/bootdev/actions/workflows/ci.yml/badge.svg) | Notely — a Go web server covering building, testing, and deploying with GitHub Actions and Google Cloud Run. | ## About diff --git a/learn-cicd/README.md b/learn-cicd/README.md index eb5dca9..36a2d4e 100644 --- a/learn-cicd/README.md +++ b/learn-cicd/README.md @@ -21,3 +21,5 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +lennago's version of Boot.dev's Notely app. diff --git a/learn-cicd/internal/auth/get_api_key_test.go b/learn-cicd/internal/auth/get_api_key_test.go new file mode 100644 index 0000000..5ac1cd9 --- /dev/null +++ b/learn-cicd/internal/auth/get_api_key_test.go @@ -0,0 +1,62 @@ +package auth + +import ( + "fmt" + "net/http" + "strings" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + key string + value string + expect string + expectErr string + }{ + { + expectErr: "no authorization header", + }, + { + key: "Authorization", + expectErr: "no authorization header", + }, + { + key: "Authorization", + value: "-", + expectErr: "malformed authorization header", + }, + { + key: "Authorization", + value: "Bearer xxxxxx", + expectErr: "malformed authorization header", + }, + { + key: "Authorization", + value: "ApiKey xxxxxx", + expect: "xxxxxx", + expectErr: "not expecting an error", + }, + } + + for i, test := range tests { + t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T) { + header := http.Header{} + header.Add(test.key, test.value) + + output, err := GetAPIKey(header) + if err != nil { + if strings.Contains(err.Error(), test.expectErr) { + return + } + t.Errorf("Unexpected: TestGetAPIKey:%v\n", err) + return + } + + if output != test.expect { + t.Errorf("Unexpected: TestGetAPIKey:%s", output) + return + } + }) + } +}