Skip to content

Commit e034161

Browse files
Merge pull request #1 from bloodsweatncode/addtests
Added ci workflow and badge
2 parents a759e37 + 9af660e commit e034161

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
tests:
9+
name: Tests
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: "1.23.0"
20+
21+
- name: Run Tests
22+
run: go test --cover ./...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ out
22
.env
33
learn-cicd-starter
44
notely
5+
.idea

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
![/badge.svg](https://github.com/bloodsweatncode/learn-cicd-starter/actions/workflows/ci.yml/badge.svg)
2+
3+
14
# learn-cicd-starter (Notely)
25

36
This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).
@@ -21,3 +24,5 @@ go build -o notely && ./notely
2124
*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`.
2225

2326
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!
27+
28+
Christian's version of Boot.dev's Notely app.

internal/auth/get_api_key_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package auth
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"strings"
7+
"testing"
8+
)
9+
10+
func TestGetApiKey(t *testing.T) {
11+
tests := []struct {
12+
key string
13+
value string
14+
expect string
15+
expectErr string
16+
}{
17+
{
18+
expectErr: "no authorization header",
19+
},
20+
{
21+
key: "Authorization",
22+
expectErr: "no authorization header",
23+
},
24+
{
25+
key: "Authorization",
26+
value: "-",
27+
expectErr: "malformed authorization header",
28+
},
29+
{
30+
key: "Authorization",
31+
value: "Bearer xxxxxx",
32+
expectErr: "malformed authorization header",
33+
},
34+
{
35+
key: "Authorization",
36+
value: "ApiKey xxxxxx",
37+
expect: "xxxxxx",
38+
expectErr: "not expecting an error",
39+
},
40+
}
41+
42+
for i, test := range tests {
43+
t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T) {
44+
header := http.Header{}
45+
header.Add(test.key, test.value)
46+
47+
output, err := GetAPIKey(header)
48+
if err != nil {
49+
if strings.Contains(err.Error(), test.expectErr) {
50+
return
51+
}
52+
t.Errorf("Unexpected: TestGetAPIKey:%v\n", err)
53+
return
54+
}
55+
56+
if output != test.expect {
57+
t.Errorf("Unexpected: TestGetAPIKey:%s", output)
58+
return
59+
}
60+
})
61+
}
62+
63+
}

0 commit comments

Comments
 (0)