Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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.26.0"

- name: -cover
run: go test ./... -cover
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# learn-cicd-starter (Notely)

![alt text goes here](https://github.com/mhmudyasien/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)
# learn-cicd-starter

This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).

Expand All @@ -21,3 +23,4 @@ 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!
Mahmoud's version of Boot.dev's Notely app.
45 changes: 45 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package auth

import (
"net/http"
"testing"
)

// Test when API key exists
func TestGetAPIKey_Valid(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
req.Header.Set("Authorization", "ApiKey 12345")

apiKey, err := GetAPIKey(req.Header) // 👈 هنا التعديل

if err != nil {
t.Errorf("expected no error, got %v", err)
}

if apiKey != "12345" {
t.Errorf("expected API key '12345', got %s", apiKey)
}
}

// Test when header is missing
func TestGetAPIKey_MissingHeader(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)

_, err := GetAPIKey(req.Header) // 👈 هنا التعديل

if err == nil {
t.Errorf("expected error, got nil")
}
}

// Test when format is wrong
func TestGetAPIKey_InvalidFormat(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
req.Header.Set("Authorization", "WrongFormat 12345")

_, err := GetAPIKey(req.Header) // 👈 هنا التعديل

if err == nil {
t.Errorf("expected error for invalid format, got nil")
}
}