File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ./...
Original file line number Diff line number Diff line change 22.env
33learn-cicd-starter
44notely
5+ .idea
Original file line number Diff line number Diff line change 1+ ![ /badge.svg] ( https://github.com/bloodsweatncode/learn-cicd-starter/actions/workflows/ci.yml/badge.svg )
2+
3+
14# learn-cicd-starter (Notely)
25
36This 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
2326You 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.
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments