From 279684fce0847e7c00b86bfe84abcf57897acd2f Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 19:32:10 +0530 Subject: [PATCH 1/7] Following boot.dev's CI/CD course instructions... --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b7..6a4d3bc2237 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! + +# Rajendra's vesion of boot.dev's notely application. \ No newline at end of file From 077aa139ebafae5484729d9af6818ea9240ef17e Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 20:24:43 +0530 Subject: [PATCH 2/7] GitHub workflow continuous integration file added --- .github/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 00000000000..a54d8248d54 --- /dev/null +++ b/.github/ci.yml @@ -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.25.1" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From a9fbc753a634ac8b7554c9ede500248a3b670d3f Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 21:17:49 +0530 Subject: [PATCH 3/7] moved to ci.yml to workflows folder --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 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 00000000000..a54d8248d54 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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.25.1" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From 06e58475f3a3eb8eb6b67bc83cd6928e91876ca4 Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 21:40:43 +0530 Subject: [PATCH 4/7] Print Go version and exit successfully --- .github/ci.yml | 22 ---------------------- .github/workflows/ci.yml | 4 ++-- 2 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml deleted file mode 100644 index a54d8248d54..00000000000 --- a/.github/ci.yml +++ /dev/null @@ -1,22 +0,0 @@ -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: Force Failure - run: (exit 1) \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a54d8248d54..521aa6bd091 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Force Failure - run: (exit 1) \ No newline at end of file + - name: Print Go version and exit successfully. + run: go version \ No newline at end of file From cada03122c6ddbbc8bb32a9eefc61f723f8ede9f Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 22:16:55 +0530 Subject: [PATCH 5/7] Unit test cases added for Auth.go --- .github/workflows/ci.yml | 2 +- internal/auth/auth_test.go | 98 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 internal/auth/auth_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 521aa6bd091..4d0ede753f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: ci +name: ci_ContinuousIntegration on: pull_request: diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 00000000000..e567fb59acf --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,98 @@ +package auth + +import ( + "errors" + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + // Define a slice of test structures with various input scenarios + tests := []struct { + name string // Name of the test case + headers http.Header // Input HTTP headers + expectedAPIKey string // Expected API Key on success + expectedError error // Expected error on failure + }{ + { + name: "Success - Correct ApiKey header", + headers: http.Header{ + "Authorization": []string{"ApiKey my-secret-api-key"}, + }, + expectedAPIKey: "my-secret-api-key", + expectedError: nil, + }, + { + name: "Failure - No Authorization header", + headers: http.Header{}, // Empty headers + expectedAPIKey: "", + expectedError: ErrNoAuthHeaderIncluded, // Matches the specific error var + }, + { + name: "Failure - Header present but empty value", + headers: http.Header{ + "Authorization": []string{""}, + }, + expectedAPIKey: "", + // This case triggers the malformed error due to the Split logic + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Failure - Malformed header - missing space/key part", + headers: http.Header{ + "Authorization": []string{"ApiKey"}, + }, + expectedAPIKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Failure - Malformed header - only value present", + headers: http.Header{ + "Authorization": []string{"only-a-key-no-prefix"}, + }, + expectedAPIKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Failure - Wrong authorization scheme (e.g., Bearer)", + headers: http.Header{ + "Authorization": []string{"Bearer some-jwt-token"}, + }, + expectedAPIKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Failure - Extra spaces in header value (library handles trim implicitly)", + headers: http.Header{ + "Authorization": []string{" ApiKey my-key-with-spaces "}, + }, + // Note: http.Header.Get() trims leading/trailing whitespace automatically. + // The Split function then handles internal spacing appropriately for this structure. + expectedAPIKey: "my-key-with-spaces", + expectedError: nil, + }, + } + + // Iterate through all defined test cases + for _, tt := range tests { + // Run each case as a subtest + t.Run(tt.name, func(t *testing.T) { + gotAPIKey, gotError := GetAPIKey(tt.headers) + + // Check for API Key match + if gotAPIKey != tt.expectedAPIKey { + t.Errorf("GetAPIKey() gotAPIKey = %v, want %v", gotAPIKey, tt.expectedAPIKey) + } + + // Check for error match + // Using Error() string comparison is generally acceptable for expected static errors in simple functions, + // but for specific known errors like ErrNoAuthHeaderIncluded, an `errors.Is` check is better practice. + if (gotError != nil && tt.expectedError != nil) && gotError.Error() != tt.expectedError.Error() { + t.Errorf("GetAPIKey() gotError = %v, want %v", gotError, tt.expectedError) + } else if (gotError != nil) != (tt.expectedError != nil) { + // Checks if one is nil and the other is not + t.Errorf("GetAPIKey() gotError presence mismatch: got %v, want %v", gotError, tt.expectedError) + } + }) + } +} From e36d6d1f39b476ebeb18c76f3c025bb820cb0940 Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 22:20:34 +0530 Subject: [PATCH 6/7] Update workflow to run all test cases --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d0ede753f8..50f8d4bf9aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,7 @@ jobs: go-version: "1.25.1" - name: Print Go version and exit successfully. - run: go version \ No newline at end of file + run: go version + + - name: Run Auth test cases + run: go test ./... \ No newline at end of file From a6536d825268faa56e5135b01d6d1e836cf338b3 Mon Sep 17 00:00:00 2001 From: Rajendra Prasad M Date: Fri, 5 Dec 2025 22:28:55 +0530 Subject: [PATCH 7/7] Code coverage in unit tests and it's badge in Read Me! --- .github/workflows/ci.yml | 2 +- README.md | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50f8d4bf9aa..d4741c631d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,4 +22,4 @@ jobs: run: go version - name: Run Auth test cases - run: go test ./... \ No newline at end of file + run: go test ./... -cover \ No newline at end of file diff --git a/README.md b/README.md index 6a4d3bc2237..d6f8092155f 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,7 @@ go build -o notely && ./notely 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! -# Rajendra's vesion of boot.dev's notely application. \ No newline at end of file +# Rajendra's vesion of boot.dev's notely application. +# Code coverage badge +![Unit Test Code Coverage](https://github.com/rpm-sconex/bootdevz-learn-cicd-starter/actions/workflows/ci.yml/badge.svg) +