Skip to content

Commit 34faa80

Browse files
committed
Break code in auth.go to test CI failure
1 parent 3502f09 commit 34faa80

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
with:
1919
go-version: "1.25.1"
2020

21-
- name: Log Go version
22-
run: echo $(go version)
21+
- name: Run unit tests
22+
run: go test ./...
2323

2424
- name: Exit
2525
run: (exit 0)

internal/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var ErrNoAuthHeaderIncluded = errors.New("no authorization header included")
1212
func GetAPIKey(headers http.Header) (string, error) {
1313
authHeader := headers.Get("Authorization")
1414
if authHeader == "" {
15-
return "", ErrNoAuthHeaderIncluded
15+
return "Ope, there was an error", ErrNoAuthHeaderIncluded
1616
}
1717
splitAuth := strings.Split(authHeader, " ")
1818
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {

internal/auth/auth_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package auth
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"testing"
7+
)
8+
9+
func TestGetAPIKey(t *testing.T) {
10+
tests := []struct{
11+
name string
12+
header http.Header
13+
want string
14+
wantErr bool
15+
}{
16+
{
17+
name: "missing auth header",
18+
header: http.Header{"Authorization": []string{""}},
19+
want: "",
20+
wantErr: true,
21+
},
22+
}
23+
24+
for _, tc := range tests {
25+
got, err := GetAPIKey(tc.header)
26+
if (err != nil) != tc.wantErr {
27+
fmt.Sprintf("Got issue in test case %s", tc.name)
28+
t.Fatalf("expected error: %v, got %v", tc.wantErr, err)
29+
}
30+
if got != tc.want {
31+
t.Errorf("expected: %q, got %q", tc.want, got)
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)