From ab8fd96278dea66b23da27727ab4133acb41b7bf Mon Sep 17 00:00:00 2001 From: lola adriana Date: Tue, 5 Aug 2025 13:25:35 +0200 Subject: [PATCH 1/9] Add Adriana's version note to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b..fa205db1d3 100644 --- a/README.md +++ b/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! +Adriana's version of Boot.dev's Notely app. + From a74c650347cf4adfb207c6a54fc1ef67ae49e939 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 13:51:24 +0200 Subject: [PATCH 2/9] Add failing CI workflow --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..da11e29497 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.23.0" + + - name: Force Failure + run: (exit 1) + From 2e55ed367550bc7f03eb246b3addb1b92abb4a21 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 14:03:49 +0200 Subject: [PATCH 3/9] Update CI to print Go version instead of failing --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da11e29497..f1fc389f93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,8 @@ jobs: with: go-version: "1.23.0" - - name: Force Failure - run: (exit 1) + + - name: Print Go Version + run: go version + From 026c7504c565ec8fe7397eddf8bd788627ee0531 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 14:31:54 +0200 Subject: [PATCH 4/9] Add unit tests for GetAPIKey function --- internal/auth/auth_test.go | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 internal/auth/auth_test.go diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..57e6080ccf --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,43 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey_ValidHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey testtoken123") + + key, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("expected no error, got: %v", err) + } + if key != "testtoken123" { + t.Errorf("expected key to be 'testtoken123', got: %s", +key) + } +} + +func TestGetAPIKey_MissingHeader(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + if err == nil { + t.Fatal("expected error for missing header, got nil") + } + if err != ErrNoAuthHeaderIncluded { + t.Errorf("expected ErrNoAuthHeaderIncluded, got: %v", err) + } +} + +func TestGetAPIKey_MalformedHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "Bearer sometoken") + + _, err := GetAPIKey(headers) + if err == nil { + t.Fatal("expected error for malformed header, got nil") + } +} + From 96c4964c1d1145612eb45b33888df7045504f896 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 15:34:00 +0200 Subject: [PATCH 5/9] Break test intentionally to verify CI failure --- .github/workflows/ci.yml | 6 ++++-- internal/auth/auth_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1fc389f93..7782c91749 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,9 @@ jobs: go-version: "1.23.0" - - name: Print Go Version - run: go version + - name: Run unit tests + run: go test ./... + + diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 57e6080ccf..1aaf9ffa96 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -13,7 +13,7 @@ func TestGetAPIKey_ValidHeader(t *testing.T) { if err != nil { t.Fatalf("expected no error, got: %v", err) } - if key != "testtoken123" { + if key != "wrongvalueerror" { t.Errorf("expected key to be 'testtoken123', got: %s", key) } From 26607e4850f8abab2a54fcb9bea73799cfeadfc9 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 15:40:53 +0200 Subject: [PATCH 6/9] Fix test after confirming CI failure works --- internal/auth/auth_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 1aaf9ffa96..57e6080ccf 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -13,7 +13,7 @@ func TestGetAPIKey_ValidHeader(t *testing.T) { if err != nil { t.Fatalf("expected no error, got: %v", err) } - if key != "wrongvalueerror" { + if key != "testtoken123" { t.Errorf("expected key to be 'testtoken123', got: %s", key) } From c95ba3842214b13dbddc62816cd05b977d7e6138 Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 15:49:53 +0200 Subject: [PATCH 7/9] Add code coverage to CI --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7782c91749..933e8b85f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,10 @@ jobs: go-version: "1.23.0" - - name: Run unit tests - run: go test ./... + - name: Run unit tests with coverage + run: go test -cover ./... + + From dbf9200950497b7be8324e7d4d542ccfe66e554f Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 16:35:37 +0200 Subject: [PATCH 8/9] Add CI status badge to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fa205db1d3..5215d90a3b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # learn-cicd-starter (Notely) +![CI +Status](https://github.com/adrianalola/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). From 2639f607a924a7eb8a8fdad9a49100a8543cf15e Mon Sep 17 00:00:00 2001 From: lola adriana Date: Wed, 6 Aug 2025 16:43:13 +0200 Subject: [PATCH 9/9] Fix CI badge URL --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 5215d90a3b..5712e263e1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # learn-cicd-starter (Notely) -![CI -Status](https://github.com/adrianalola/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) +![CI Status](https://github.com/adrianalola/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).