@@ -491,3 +491,95 @@ func TestKidRun(t *testing.T) {
491491	assert .Equal (t , "application/json" , resp .Header .Get ("Content-Type" ))
492492	assert .Equal (t , "{\" message\" :\" healthy\" }\n " , string (body ))
493493}
494+ 
495+ func  TestKidStatic (t  * testing.T ) {
496+ 	k  :=  New ()
497+ 
498+ 	k .Static ("/static/" , "testdata/static" )
499+ 
500+ 	testCases  :=  []struct  {
501+ 		name                string 
502+ 		req                 * http.Request 
503+ 		res                 * httptest.ResponseRecorder 
504+ 		expectedStatusCode  int 
505+ 		expectedContent     string 
506+ 	}{
507+ 		{
508+ 			name :               "Serving main.html" ,
509+ 			req :                httptest .NewRequest (http .MethodGet , "/static/main.html" , nil ),
510+ 			res :                httptest .NewRecorder (),
511+ 			expectedStatusCode : http .StatusOK ,
512+ 			expectedContent :    "main" ,
513+ 		},
514+ 		{
515+ 			name :               "Serving page.html in pages directory" ,
516+ 			req :                httptest .NewRequest (http .MethodGet , "/static/pages/page.html" , nil ),
517+ 			res :                httptest .NewRecorder (),
518+ 			expectedStatusCode : http .StatusOK ,
519+ 			expectedContent :    "page" ,
520+ 		},
521+ 		{
522+ 			name :               "Serving pages/index.html" ,
523+ 			req :                httptest .NewRequest (http .MethodGet , "/static/pages/" , nil ),
524+ 			res :                httptest .NewRecorder (),
525+ 			expectedStatusCode : http .StatusOK ,
526+ 			expectedContent :    "index" ,
527+ 		},
528+ 		{
529+ 			name :               "Non-existent" ,
530+ 			req :                httptest .NewRequest (http .MethodGet , "/static/doesn't-exist.html" , nil ),
531+ 			res :                httptest .NewRecorder (),
532+ 			expectedStatusCode : http .StatusNotFound ,
533+ 			expectedContent :    "404 page not found\n " ,
534+ 		},
535+ 	}
536+ 
537+ 	for  _ , testCase  :=  range  testCases  {
538+ 		t .Run (testCase .name , func (t  * testing.T ) {
539+ 			k .ServeHTTP (testCase .res , testCase .req )
540+ 
541+ 			assert .Equal (t , testCase .expectedStatusCode , testCase .res .Code )
542+ 			assert .Equal (t , testCase .expectedContent , testCase .res .Body .String ())
543+ 		})
544+ 	}
545+ 
546+ }
547+ 
548+ func  TestKidStaticFS (t  * testing.T ) {
549+ 	k  :=  New ()
550+ 
551+ 	k .StaticFS ("/static/" , http .Dir ("testdata/static" ))
552+ 
553+ 	testCases  :=  []struct  {
554+ 		name                string 
555+ 		req                 * http.Request 
556+ 		res                 * httptest.ResponseRecorder 
557+ 		expectedStatusCode  int 
558+ 		expectedContent     string 
559+ 	}{
560+ 		{
561+ 			name :               "Serving main.html" ,
562+ 			req :                httptest .NewRequest (http .MethodGet , "/static/main.html" , nil ),
563+ 			res :                httptest .NewRecorder (),
564+ 			expectedStatusCode : http .StatusOK ,
565+ 			expectedContent :    "main" ,
566+ 		},
567+ 		{
568+ 			name :               "Serving page.html in pages directory" ,
569+ 			req :                httptest .NewRequest (http .MethodGet , "/static/pages/page.html" , nil ),
570+ 			res :                httptest .NewRecorder (),
571+ 			expectedStatusCode : http .StatusOK ,
572+ 			expectedContent :    "page" ,
573+ 		},
574+ 	}
575+ 
576+ 	for  _ , testCase  :=  range  testCases  {
577+ 		t .Run (testCase .name , func (t  * testing.T ) {
578+ 			k .ServeHTTP (testCase .res , testCase .req )
579+ 
580+ 			assert .Equal (t , testCase .expectedStatusCode , testCase .res .Code )
581+ 			assert .Equal (t , testCase .expectedContent , testCase .res .Body .String ())
582+ 		})
583+ 	}
584+ 
585+ }
0 commit comments