diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000000..81390f0ca12 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,21 @@ +name: cd +on: + push: + branches: [main] + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Build + run: ./scripts/buildprod.sh \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..1fd88003222 --- /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.25.1" + + - name: run tests + run: go test -cover ./... + \ No newline at end of file diff --git a/README.md b/README.md index c2bec0368b7..9b7eff34668 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ +[![ci](https://github.com/itselcid/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/itselcid/learn-cicd-starter/actions/workflows/ci.yml) + # learn-cicd-starter (Notely) +elcid's version of Boot.dev's Notely app . This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). ## Local Development @@ -18,6 +21,6 @@ Run the server: go build -o notely && ./notely ``` -*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. +_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! +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! diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 00000000000..67a6a130652 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,67 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + expectedKey string + expectedError error + }{ + { + name: "Valid API Key", + headers: http.Header{ + "Authorization": []string{"ApiKey test-api-key-123"}, + }, + expectedKey: "test-api-key-123", + expectedError: nil, + }, + { + name: "No Authorization Header", + headers: http.Header{}, + expectedKey: "", + expectedError: ErrNoAuthHeaderIncluded, + }, + { + name: "Malformed Authorization Header - Missing ApiKey prefix", + headers: http.Header{ + "Authorization": []string{"Bearer test-token"}, + }, + expectedKey: "", + expectedError: nil, // Will check error message instead + }, + { + name: "Malformed Authorization Header - No space", + headers: http.Header{ + "Authorization": []string{"ApiKeytest-api-key"}, + }, + expectedKey: "", + expectedError: nil, // Will check error message instead + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + key, err := GetAPIKey(tt.headers) + + if key != tt.expectedKey { + t.Errorf("Expected key %q, got %q", tt.expectedKey, key) + } + + if tt.expectedError != nil { + if err != tt.expectedError { + t.Errorf("Expected error %v, got %v", tt.expectedError, err) + } + } else if tt.name != "Valid API Key" { + // For malformed header tests, just check that an error occurred + if err == nil { + t.Errorf("Expected an error for malformed header, got nil") + } + } + }) + } +}