Skip to content

Commit

Permalink
session-5: Add test stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Mikitiuk committed Nov 11, 2023
1 parent 3758c85 commit 6a1d640
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 7 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ jobs:
with:
go-version: '1.21'

- name: Build
- name: Build quiz
run: go build -v ./quiz/main.go

- name: Test
run: cd quiz && go test -run .
- name: Test quiz
run: cd $GITHUB_WORKSPACE && cd quiz && go test -run .

- name: Build urlshort
run: go build -v ./urlshort/main.go

- name: Test urlshort
run: cd $GITHUB_WORKSPACE && cd urlshort && go test -run .
14 changes: 10 additions & 4 deletions quiz/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package main

import "testing"

func TestHello(t *testing.T) {
want := "Hello world"
if got := Hello("world"); got != want {
t.Errorf("Hello = %q, want: %q", got, want)
func Test_main(t *testing.T) {
tests := []struct {
name string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
main()
})
}
}
82 changes: 82 additions & 0 deletions urlshort/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package urlshort

import (
"net/http"
"reflect"
"testing"
)

func TestMapHandler(t *testing.T) {
type args struct {
pathsToUrls map[string]string
fallback http.Handler
}
tests := []struct {
name string
args args
want http.HandlerFunc
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MapHandler(tt.args.pathsToUrls, tt.args.fallback); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MapHandler() = %v, want %v", got, tt.want)
}
})
}
}

func TestYAMLHandler(t *testing.T) {
type args struct {
yml []byte
fallback http.Handler
}
tests := []struct {
name string
args args
want http.HandlerFunc
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := YAMLHandler(tt.args.yml, tt.args.fallback)
if (err != nil) != tt.wantErr {
t.Errorf("YAMLHandler() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("YAMLHandler() = %v, want %v", got, tt.want)
}
})
}
}

func TestJSONHandler(t *testing.T) {
type args struct {
jsonInput []byte
fallback http.Handler
}
tests := []struct {
name string
args args
want http.HandlerFunc
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := JSONHandler(tt.args.jsonInput, tt.args.fallback)
if (err != nil) != tt.wantErr {
t.Errorf("JSONHandler() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("JSONHandler() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 6a1d640

Please sign in to comment.