diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index def5fa6..cd3dde6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 . diff --git a/quiz/main_test.go b/quiz/main_test.go index 80cf9bc..35231c6 100644 --- a/quiz/main_test.go +++ b/quiz/main_test.go @@ -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() + }) } } diff --git a/urlshort/handler_test.go b/urlshort/handler_test.go new file mode 100644 index 0000000..83a8663 --- /dev/null +++ b/urlshort/handler_test.go @@ -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) + } + }) + } +}