From aabbcb882d77cb93613bcc966706189f5cc83cb2 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 22 Sep 2025 02:20:41 +0200 Subject: [PATCH 01/29] =?UTF-8?q?Erste=20Test=C3=A4nderungen=20im=20Branch?= =?UTF-8?q?=20doris-tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test.txt diff --git a/test.txt b/test.txt new file mode 100644 index 0000000000..276e7895a0 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +test text \ No newline at end of file From 88aacd41d8f83c5f8f9cf989c4e70480255e6f35 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 23 Sep 2025 15:01:42 +0200 Subject: [PATCH 02/29] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b..259be1a5aa 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! + +Doris Lederle's version of Boot.dev's Notely app. \ No newline at end of file From 8dc2dc5418d0f4d0fe035bae92597b1b0e3c56f6 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 23 Sep 2025 23:39:16 +0200 Subject: [PATCH 03/29] Add CI workflow --- .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 0000000000..3ed19a3db1 --- /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 0e0e9e392c42b0e07299bd28dc28ecba9ce4b027 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Wed, 24 Sep 2025 00:11:17 +0200 Subject: [PATCH 04/29] Update CI to print Go version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ed19a3db1..d270e0e3c6 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 + run: go version \ No newline at end of file From 707954b1086cd956dcbbf4e22daf198a955288e3 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 02:11:35 +0200 Subject: [PATCH 05/29] Adding testfile and broken code for testing --- .github/workflows/ci.yml | 11 ++++- internal/auth/auth.go | 6 ++- internal/auth/auth_test.go | 83 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 internal/auth/auth_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d270e0e3c6..5db343b2e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,12 @@ jobs: with: go-version: "1.25.1" - - name: Print Go version - run: go version \ No newline at end of file + # - name: Print Go version + # run: go version + - name: Run Go Tests + run: go test ./... + + #- name: Run Go tests + #- name: Run CLI test + # run: | + # AUTH_HEADER="ApiKey testkey" go run cmd/notely/main.go \ No newline at end of file diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf63..f83cec86c1 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -11,9 +11,11 @@ var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") // GetAPIKey - func GetAPIKey(headers http.Header) (string, error) { authHeader := headers.Get("Authorization") - if authHeader == "" { + headers.Set("Authorization", "") //braking the code for test + + /*if authHeader == "" { return "", ErrNoAuthHeaderIncluded - } + }*/ splitAuth := strings.Split(authHeader, " ") if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" { return "", errors.New("malformed authorization header") diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..45b3e8ee12 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,83 @@ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey_ValidHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123") + //headers.Set("Authorization", "abc123") + + got, err := GetAPIKey(headers) + want := "abc123" + //want := "wrongkey" + + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != want { + t.Errorf("Expected API key %q, got %q", want, got) + } +} + +func TestGetAPIKey_MissingHeader(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + if err != ErrNoAuthHeaderIncluded { + t.Errorf("Expected error %v, got %v", ErrNoAuthHeaderIncluded, err) + } +} + +func TestGetAPIKey_MalformedHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "Bearer abc123") + + _, err := GetAPIKey(headers) + if err == nil || err.Error() != "malformed authorization header" { + t.Errorf("Expected malformed header error, got %v", err) + } +} + +func TestGetAPIKey_EmptyKey(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey ") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error for empty key, got %v", err) + } + if got != "" { + t.Errorf("Expected empty string, got %q", got) + } +} + +/* +func TestGetAPIKey_ExtraSpaces(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != "abc123" { + t.Errorf("Expected 'abc123', got %q", got) + } +} +*/ + +func TestGetAPIKey_MultipleParts(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123 extra") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != "abc123" { + t.Errorf("Expected 'abc123', got %q", got) + } +} From 7539cbc758400c642791bd6f3cea62105828a3be Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 02:16:41 +0200 Subject: [PATCH 06/29] Changed ci.yml - make it work --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5db343b2e7..6cbc78f2a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Run Go Tests run: go test ./... - #- name: Run Go tests - #- name: Run CLI test - # run: | - # AUTH_HEADER="ApiKey testkey" go run cmd/notely/main.go \ No newline at end of file + - name: Run Go tests + - name: Run CLI test + run: | + AUTH_HEADER="ApiKey testkey" go run cmd/notely/main.go \ No newline at end of file From 20f381bd7978a132e4f2b2532d52648b10b63518 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 02:51:51 +0200 Subject: [PATCH 07/29] Break GetAPIKey for CI test --- .github/workflows/ci.yml | 7 ------- internal/auth/auth.go | 8 ++++---- internal/auth/auth_test.go | 3 ++- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cbc78f2a8..a91bad6fa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,12 +18,5 @@ jobs: with: go-version: "1.25.1" - # - name: Print Go version - # run: go version - name: Run Go Tests run: go test ./... - - - name: Run Go tests - - name: Run CLI test - run: | - AUTH_HEADER="ApiKey testkey" go run cmd/notely/main.go \ No newline at end of file diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f83cec86c1..bdfbe08845 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -11,15 +11,15 @@ var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") // GetAPIKey - func GetAPIKey(headers http.Header) (string, error) { authHeader := headers.Get("Authorization") - headers.Set("Authorization", "") //braking the code for test - /*if authHeader == "" { + if authHeader == "" { return "", ErrNoAuthHeaderIncluded - }*/ + } splitAuth := strings.Split(authHeader, " ") if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" { return "", errors.New("malformed authorization header") } - return splitAuth[1], nil + //return splitAuth[1], nil + return "wrong-key", nil //temporarily broken code for testing } diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 45b3e8ee12..b0f47790d3 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -67,7 +67,7 @@ func TestGetAPIKey_ExtraSpaces(t *testing.T) { t.Errorf("Expected 'abc123', got %q", got) } } -*/ + func TestGetAPIKey_MultipleParts(t *testing.T) { headers := http.Header{} @@ -81,3 +81,4 @@ func TestGetAPIKey_MultipleParts(t *testing.T) { t.Errorf("Expected 'abc123', got %q", got) } } +*/ From b8942e75e2863b6788775e9acf7737002646e9d4 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 02:57:18 +0200 Subject: [PATCH 08/29] Fixed GetAPIKey --- internal/auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index bdfbe08845..5d632791a3 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -20,6 +20,6 @@ func GetAPIKey(headers http.Header) (string, error) { return "", errors.New("malformed authorization header") } - //return splitAuth[1], nil - return "wrong-key", nil //temporarily broken code for testing + return splitAuth[1], nil + //return "wrong-key", nil //temporarily broken code for testing } From a2a799ce9c17952796fa3e545feda0c4e65e9ce8 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 21:22:43 +0200 Subject: [PATCH 09/29] Prepare vor CH2LS3 --- internal/auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 5d632791a3..bdfbe08845 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -20,6 +20,6 @@ func GetAPIKey(headers http.Header) (string, error) { return "", errors.New("malformed authorization header") } - return splitAuth[1], nil - //return "wrong-key", nil //temporarily broken code for testing + //return splitAuth[1], nil + return "wrong-key", nil //temporarily broken code for testing } From 5e007c9143b4ca5706668a70143880fa0b87c097 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 21:52:07 +0200 Subject: [PATCH 10/29] Fix code and add coverage step --- .github/workflows/ci.yml | 7 ++++++- internal/auth/auth.go | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a91bad6fa2..27a019d96b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,9 @@ jobs: go-version: "1.25.1" - name: Run Go Tests - run: go test ./... + run: | + go test ./... + go test -cover ./... + + #- name: Run Go test with coverage + # run: go test -cover ./... diff --git a/internal/auth/auth.go b/internal/auth/auth.go index bdfbe08845..5d632791a3 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -20,6 +20,6 @@ func GetAPIKey(headers http.Header) (string, error) { return "", errors.New("malformed authorization header") } - //return splitAuth[1], nil - return "wrong-key", nil //temporarily broken code for testing + return splitAuth[1], nil + //return "wrong-key", nil //temporarily broken code for testing } From 5b584be177347d8e68c0efaaad219fc15c13506a Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Fri, 26 Sep 2025 23:32:07 +0200 Subject: [PATCH 11/29] Split test and coverage steps --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27a019d96b..ebfc532dbd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,7 @@ jobs: go-version: "1.25.1" - name: Run Go Tests - run: | - go test ./... - go test -cover ./... - - #- name: Run Go test with coverage - # run: go test -cover ./... + run: go test ./... + + - name: Run Go test with coverage + run: go test -cover ./... From 555444bbaeb8ba923f5609ce06d381f4a406c9ce Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Sat, 27 Sep 2025 18:46:57 +0200 Subject: [PATCH 12/29] added README Badge for Test --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 259be1a5aa..b493b3d58c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# README Badge for Tests +[![ci](https://github.com/DorisLederle/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/DorisLederle/learn-cicd-starter/actions/workflows/ci.yml) + # learn-cicd-starter (Notely) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). From 5014c1661405dad2f22a067f3e14fa695074b11f Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 00:04:01 +0200 Subject: [PATCH 13/29] Add Style job: Go Formatting --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebfc532dbd..32e3b4d220 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,24 @@ jobs: - name: Run Go test with coverage run: go test -cover ./... + + style: + name: Style + 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 Go Formatting + run: | + go fmt ./... + test -z "$(go fmt ./...)" + + + \ No newline at end of file From 3e416169cfbf95435479c8e2e9f1b0ff089e022e Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 00:23:12 +0200 Subject: [PATCH 14/29] Style-Job Formating: split into two steps --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32e3b4d220..19ac69d158 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,9 +38,10 @@ jobs: go-version: "1.25.1" - name: Run Go Formatting - run: | - go fmt ./... - test -z "$(go fmt ./...)" + run: go fmt ./... + + - name: Run Test -z + run: test -z "$(go fmt ./...)" \ No newline at end of file From e6c4ca98817eef7f2f26bbaa5479c87fae98e35a Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 00:24:45 +0200 Subject: [PATCH 15/29] Style-Job Formating: split into two steps and reduced empty lines --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19ac69d158..6f592b1ba8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,5 @@ jobs: run: go fmt ./... - name: Run Test -z - run: test -z "$(go fmt ./...)" - - + run: test -z "$(go fmt ./...)" \ No newline at end of file From da94518b929cecfca39a95273a073e577f7f69ac Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 00:41:28 +0200 Subject: [PATCH 16/29] Style-Job Formating: go formating, test -z --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f592b1ba8..a76f016634 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,9 +37,9 @@ jobs: with: go-version: "1.25.1" - - name: Run Go Formatting - run: go fmt ./... - - name: Run Test -z run: test -z "$(go fmt ./...)" + + - name: Run Go Formatting + run: go fmt ./... \ No newline at end of file From 5f671fe4f730cb6359805102bf7e94aa4a303386 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 00:50:04 +0200 Subject: [PATCH 17/29] Style-Job Formating: go formating, test -z; after go formatting --- README.md | 4 + internal/auth/auth_test.go | 168 ++++++++++++++++++------------------- main.go | 4 +- 3 files changed, 89 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index b493b3d58c..9711e7d41a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # README Badge for Tests [![ci](https://github.com/DorisLederle/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/DorisLederle/learn-cicd-starter/actions/workflows/ci.yml) + + + + # learn-cicd-starter (Notely) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index b0f47790d3..4047953468 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -1,84 +1,84 @@ -package auth - -import ( - "net/http" - "testing" -) - -func TestGetAPIKey_ValidHeader(t *testing.T) { - headers := http.Header{} - headers.Set("Authorization", "ApiKey abc123") - //headers.Set("Authorization", "abc123") - - got, err := GetAPIKey(headers) - want := "abc123" - //want := "wrongkey" - - if err != nil { - t.Fatalf("Expected no error, got %v", err) - } - if got != want { - t.Errorf("Expected API key %q, got %q", want, got) - } -} - -func TestGetAPIKey_MissingHeader(t *testing.T) { - headers := http.Header{} - - _, err := GetAPIKey(headers) - if err != ErrNoAuthHeaderIncluded { - t.Errorf("Expected error %v, got %v", ErrNoAuthHeaderIncluded, err) - } -} - -func TestGetAPIKey_MalformedHeader(t *testing.T) { - headers := http.Header{} - headers.Set("Authorization", "Bearer abc123") - - _, err := GetAPIKey(headers) - if err == nil || err.Error() != "malformed authorization header" { - t.Errorf("Expected malformed header error, got %v", err) - } -} - -func TestGetAPIKey_EmptyKey(t *testing.T) { - headers := http.Header{} - headers.Set("Authorization", "ApiKey ") - - got, err := GetAPIKey(headers) - if err != nil { - t.Fatalf("Expected no error for empty key, got %v", err) - } - if got != "" { - t.Errorf("Expected empty string, got %q", got) - } -} - -/* -func TestGetAPIKey_ExtraSpaces(t *testing.T) { - headers := http.Header{} - headers.Set("Authorization", "ApiKey abc123") - - got, err := GetAPIKey(headers) - if err != nil { - t.Fatalf("Expected no error, got %v", err) - } - if got != "abc123" { - t.Errorf("Expected 'abc123', got %q", got) - } -} - - -func TestGetAPIKey_MultipleParts(t *testing.T) { - headers := http.Header{} - headers.Set("Authorization", "ApiKey abc123 extra") - - got, err := GetAPIKey(headers) - if err != nil { - t.Fatalf("Expected no error, got %v", err) - } - if got != "abc123" { - t.Errorf("Expected 'abc123', got %q", got) - } -} -*/ +package auth + +import ( + "net/http" + "testing" +) + +func TestGetAPIKey_ValidHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123") + //headers.Set("Authorization", "abc123") + + got, err := GetAPIKey(headers) + want := "abc123" + //want := "wrongkey" + + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != want { + t.Errorf("Expected API key %q, got %q", want, got) + } +} + +func TestGetAPIKey_MissingHeader(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + if err != ErrNoAuthHeaderIncluded { + t.Errorf("Expected error %v, got %v", ErrNoAuthHeaderIncluded, err) + } +} + +func TestGetAPIKey_MalformedHeader(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "Bearer abc123") + + _, err := GetAPIKey(headers) + if err == nil || err.Error() != "malformed authorization header" { + t.Errorf("Expected malformed header error, got %v", err) + } +} + +func TestGetAPIKey_EmptyKey(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey ") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error for empty key, got %v", err) + } + if got != "" { + t.Errorf("Expected empty string, got %q", got) + } +} + +/* +func TestGetAPIKey_ExtraSpaces(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != "abc123" { + t.Errorf("Expected 'abc123', got %q", got) + } +} + + +func TestGetAPIKey_MultipleParts(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey abc123 extra") + + got, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if got != "abc123" { + t.Errorf("Expected 'abc123', got %q", got) + } +} +*/ diff --git a/main.go b/main.go index 19d7366c5f..d583eed5f5 100644 --- a/main.go +++ b/main.go @@ -17,9 +17,7 @@ import ( _ "github.com/tursodatabase/libsql-client-go/libsql" ) -type apiConfig struct { - DB *database.Queries -} +type apiConfig struct{ DB *database.Queries } //go:embed static/* var staticFiles embed.FS From 89e568d211e5e7109014aa6cd5409847bf734b2d Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 29 Sep 2025 14:23:19 +0200 Subject: [PATCH 18/29] Added linting with staticcheck to ci.yml and unused function to main.go --- .github/workflows/ci.yml | 3 +++ main.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a76f016634..389f42918f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,7 @@ jobs: - name: Run Go Formatting run: go fmt ./... + + - name: Run Go Linting + run: staticcheck ./... \ No newline at end of file diff --git a/main.go b/main.go index d583eed5f5..06f55878a2 100644 --- a/main.go +++ b/main.go @@ -94,3 +94,8 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } + +func unused() { + // this function does nothing + // and is called nowhere +} From aa7b3de65da4680a2e25c2aa7e5f91e9b81257c6 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 30 Sep 2025 02:20:29 +0200 Subject: [PATCH 19/29] Add step staticcheck installation to Style job --- .github/workflows/ci.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 389f42918f..d4dabd769c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,11 +38,16 @@ jobs: go-version: "1.25.1" - name: Run Test -z - run: test -z "$(go fmt ./...)" - - - name: Run Go Formatting - run: go fmt ./... + run: | + test -z "$(go fmt ./...)" + go fmt ./... + #- name: Run Go Formatting + # run: go fmt ./... + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + - name: Run Go Linting run: staticcheck ./... \ No newline at end of file From 02bf81363f9b400125c2fe0da5da4c5ae93c7368 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 30 Sep 2025 02:29:07 +0200 Subject: [PATCH 20/29] Unused fuction made to comment / removed --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 06f55878a2..1f8d670999 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,7 @@ func main() { log.Fatal(srv.ListenAndServe()) } -func unused() { +/*func unused() { // this function does nothing // and is called nowhere -} +}*/ From 6f1a97f7e4bc7d027d982e4b383e901e58ea5053 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 30 Sep 2025 03:10:09 +0200 Subject: [PATCH 21/29] Added 2 steps to Job Tests: -Install gosec and -Run gosec --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4dabd769c..be08ec4cab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,13 @@ jobs: - name: Run Go test with coverage run: go test -cover ./... + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run gosec + run: gosec ./... + style: name: Style @@ -47,7 +54,7 @@ jobs: - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest - + - name: Run Go Linting run: staticcheck ./... \ No newline at end of file From 40d804f356fbf124bdcd433e54463bfb412af460 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 30 Sep 2025 11:59:25 +0200 Subject: [PATCH 22/29] Fix gosec issues: add ReadHeaderTimeout and handle w.Write error --- json.go | 5 ++++- main.go | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e1..0ca35ff6ac 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,8 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + //w.Write(dat) //gosec: Errorhandling hinzufügen + if _, err := w.Write(dat); err != nil { + log.Printf("error writing response: %v", err) + } } diff --git a/main.go b/main.go index 1f8d670999..018b6fdc2b 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -87,8 +88,9 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: 5 * time.Second, //gosec: schützt vor Slowlories } log.Printf("Serving on port: %s\n", port) From f5db4ef4a26372620307b691fc1b488372005bf4 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Thu, 2 Oct 2025 04:34:50 +0200 Subject: [PATCH 23/29] Added new workflow cd.yml with Job 'Deploy' --- .github/workflows/cd.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000000..8458ba81a0 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,25 @@ +# new workflow for continuous deployment +# the ci workflow runs when a pull request is opened, +# but a cd workflow runs when a pull request is merged +# (or when code is pushed directly to the main branch). + +on: + push: + branches: [main] + +jobs: + tests: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Setup Go toolchain + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Build the app + uses: scripts/buildprod.sh \ No newline at end of file From cd8c63fb719b378a81aad50cf028ed89249d4273 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Thu, 2 Oct 2025 04:48:59 +0200 Subject: [PATCH 24/29] Added Dockerfile and changed main.go for Docker --- Dockerfile | 3 ++- main.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2be3d18b81..5d411a379c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM --platform=linux/amd64 debian:stable-slim +#FROM --platform=linux/amd64 debian:stable-slim +FROM debian:stable-slim RUN apt-get update && apt-get install -y ca-certificates diff --git a/main.go b/main.go index 018b6fdc2b..3959bdf608 100644 --- a/main.go +++ b/main.go @@ -90,7 +90,7 @@ func main() { srv := &http.Server{ Addr: ":" + port, Handler: router, - ReadHeaderTimeout: 5 * time.Second, //gosec: schützt vor Slowlories + ReadHeaderTimeout: 5 * time.Second, //gosec: schuetzt vor Slowlories } log.Printf("Serving on port: %s\n", port) From 504c796347d9393e022ba7d02ffc6e8b3f5956ce Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Thu, 2 Oct 2025 05:16:15 +0200 Subject: [PATCH 25/29] Fix cd.yml: use run instead of uses for build script --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 8458ba81a0..ba6b584313 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -22,4 +22,4 @@ jobs: go-version: "1.25.1" - name: Build the app - uses: scripts/buildprod.sh \ No newline at end of file + run: ./scripts/buildprod.sh \ No newline at end of file From 962610f41b72bf7db2f5a4438d94880e95ca5847 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Thu, 2 Oct 2025 05:55:17 +0200 Subject: [PATCH 26/29] =?UTF-8?q?Workflow-Trigger=20f=C3=BCr=20Testphase?= =?UTF-8?q?=20auf=20push=20in=20addtests=20umgestellt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ba6b584313..3cc5ee1932 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -5,10 +5,10 @@ on: push: - branches: [main] + branches: [addtests] # zum Testen [addtests], für Produktion: [main] jobs: - tests: + deploy: name: Deploy runs-on: ubuntu-latest From 9eda18fcac5c929d3c7defdf6879e2eda5406378 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 6 Oct 2025 06:07:53 +0200 Subject: [PATCH 27/29] Add GitHub Action to build and push Docker image --- .github/workflows/main.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..c38249a128 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,30 @@ +# Die Datei, die bei jedem Push auf den main-Branch automatisch: +# 1. Mit GCP authentifiziert +# 2. Das Docker-Image baut +# 3. Es in die Artifact Registry hochlaedt + +name: Build and Push to Artifact Registry + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up gcloud CLI + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: ${{ secrets.GCP_CREDENTIALS }} + project_id: tensile-core-474113-t6 + export_default_credentials: true + + - name: Build and push Docker image + run: | + gcloud builds submit --tag us-central1-docker.pkg.dev/tensile-core-474113-t6/notely-ar-repo/notely:latest . \ No newline at end of file From 352806bb021654158abdb06264186e9d7d5f9fa0 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Mon, 6 Oct 2025 06:55:11 +0200 Subject: [PATCH 28/29] main.yml Authentifizierung angepasst, Add GitHub Action to build and push Docker image --- .github/workflows/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c38249a128..d961b9e93b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,13 +18,16 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + - name: Set up gcloud CLI uses: google-github-actions/setup-gcloud@v1 with: - service_account_key: ${{ secrets.GCP_CREDENTIALS }} project_id: tensile-core-474113-t6 - export_default_credentials: true - + - name: Build and push Docker image run: | gcloud builds submit --tag us-central1-docker.pkg.dev/tensile-core-474113-t6/notely-ar-repo/notely:latest . \ No newline at end of file From 0993819e2376bde7bdc03705890715a6ce2d8725 Mon Sep 17 00:00:00 2001 From: Doris Lederle Date: Tue, 7 Oct 2025 00:38:21 +0200 Subject: [PATCH 29/29] Fix build workflow and add logging --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d961b9e93b..28c9b0625e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,13 @@ jobs: uses: google-github-actions/setup-gcloud@v1 with: project_id: tensile-core-474113-t6 - + + - name: Show gcloud config + run: gcloud config list + + - name: Who am I + run: gcloud auth list + - name: Build and push Docker image run: | gcloud builds submit --tag us-central1-docker.pkg.dev/tensile-core-474113-t6/notely-ar-repo/notely:latest . \ No newline at end of file