From f51458c8d4cf551af3132768d24eda879a70ec4b Mon Sep 17 00:00:00 2001 From: nabbat Date: Tue, 24 Oct 2023 00:33:21 +0200 Subject: [PATCH] iter6 processing --- internal/handlers/urlhandlers_test.go | 167 +++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 2 deletions(-) diff --git a/internal/handlers/urlhandlers_test.go b/internal/handlers/urlhandlers_test.go index c1a77b6..3056c2d 100644 --- a/internal/handlers/urlhandlers_test.go +++ b/internal/handlers/urlhandlers_test.go @@ -1,7 +1,9 @@ package handlers import ( + "github.com/gorilla/mux" "github.com/nabbat/23_kogorta_shotener/internal/envirements" + "github.com/nabbat/23_kogorta_shotener/internal/liblog" urlstorage "github.com/nabbat/23_kogorta_shotener/internal/storage" "net/http" "reflect" @@ -31,6 +33,7 @@ func TestPanicHandler(t *testing.T) { func TestRedirectHandler_HandleRedirect(t *testing.T) { type args struct { storage *urlstorage.URLStorage + log liblog.Logger } tests := []struct { name string @@ -42,17 +45,58 @@ func TestRedirectHandler_HandleRedirect(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { rh := &RedirectHandler{} - if got := rh.HandleRedirect(tt.args.storage); !reflect.DeepEqual(got, tt.want) { + if got := rh.HandleRedirect(tt.args.storage, tt.args.log); !reflect.DeepEqual(got, tt.want) { t.Errorf("HandleRedirect() = %v, want %v", got, tt.want) } }) } } +func TestRequestLoggingMiddleware(t *testing.T) { + type args struct { + log liblog.Logger + } + tests := []struct { + name string + args args + want mux.MiddlewareFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := RequestLoggingMiddleware(tt.args.log); !reflect.DeepEqual(got, tt.want) { + t.Errorf("RequestLoggingMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestResponseLoggingMiddleware(t *testing.T) { + type args struct { + log liblog.Logger + } + tests := []struct { + name string + args args + want mux.MiddlewareFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := ResponseLoggingMiddleware(tt.args.log); !reflect.DeepEqual(got, tt.want) { + t.Errorf("ResponseLoggingMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} + func TestShortenURLHandler_HandleShortenURL(t *testing.T) { type args struct { storage *urlstorage.URLStorage c *envirements.EnvConfig + log liblog.Logger } tests := []struct { name string @@ -64,9 +108,128 @@ func TestShortenURLHandler_HandleShortenURL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { sh := &ShortenURLHandler{} - if got := sh.HandleShortenURL(tt.args.storage, tt.args.c); !reflect.DeepEqual(got, tt.want) { + if got := sh.HandleShortenURL(tt.args.storage, tt.args.c, tt.args.log); !reflect.DeepEqual(got, tt.want) { t.Errorf("HandleShortenURL() = %v, want %v", got, tt.want) } }) } } + +func Test_responseWriterWrapper_Size(t *testing.T) { + type fields struct { + ResponseWriter http.ResponseWriter + status int + size int + } + tests := []struct { + name string + fields fields + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rw := &responseWriterWrapper{ + ResponseWriter: tt.fields.ResponseWriter, + status: tt.fields.status, + size: tt.fields.size, + } + if got := rw.Size(); got != tt.want { + t.Errorf("Size() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_responseWriterWrapper_Status(t *testing.T) { + type fields struct { + ResponseWriter http.ResponseWriter + status int + size int + } + tests := []struct { + name string + fields fields + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rw := &responseWriterWrapper{ + ResponseWriter: tt.fields.ResponseWriter, + status: tt.fields.status, + size: tt.fields.size, + } + if got := rw.Status(); got != tt.want { + t.Errorf("Status() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_responseWriterWrapper_Write(t *testing.T) { + type fields struct { + ResponseWriter http.ResponseWriter + status int + size int + } + type args struct { + b []byte + } + tests := []struct { + name string + fields fields + args args + want int + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rw := &responseWriterWrapper{ + ResponseWriter: tt.fields.ResponseWriter, + status: tt.fields.status, + size: tt.fields.size, + } + got, err := rw.Write(tt.args.b) + if (err != nil) != tt.wantErr { + t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("Write() got = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_responseWriterWrapper_WriteHeader(t *testing.T) { + type fields struct { + ResponseWriter http.ResponseWriter + status int + size int + } + type args struct { + status int + } + tests := []struct { + name string + fields fields + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rw := &responseWriterWrapper{ + ResponseWriter: tt.fields.ResponseWriter, + status: tt.fields.status, + size: tt.fields.size, + } + rw.WriteHeader(tt.args.status) + }) + } +}