@@ -835,20 +835,22 @@ func Test_Health(t *testing.T) {
835835}
836836
837837func Test_Root (t * testing.T ) {
838+ const sha = "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36"
838839 tests := []struct {
839- name string
840- root * x509.Certificate
841- err error
842- statusCode int
840+ name string
841+ root * x509.Certificate
842+ err error
843+ expectedMsg string
844+ statusCode int
843845 }{
844- {"ok" , parseCertificate (rootPEM ), nil , 200 },
845- {"fail" , nil , fmt .Errorf ("not found" ), 404 },
846+ {"ok" , parseCertificate (rootPEM ), nil , "" , 200 },
847+ {"fail" , nil , fmt .Errorf ("not found" ), fmt . Sprintf ( "root with fingerprint %s was not found" , sha ), 404 },
846848 }
847849
848850 // Request with chi context
849851 chiCtx := chi .NewRouteContext ()
850- chiCtx .URLParams .Add ("sha" , "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36" )
851- req := httptest .NewRequest ("GET" , "http://example.com/root/efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36" , http .NoBody )
852+ chiCtx .URLParams .Add ("sha" , sha )
853+ req := httptest .NewRequest ("GET" , "http://example.com/root/" + sha , http .NoBody )
852854 req = req .WithContext (context .WithValue (context .Background (), chi .RouteCtxKey , chiCtx ))
853855
854856 expected := []byte (`{"ca":"` + strings .ReplaceAll (rootPEM , "\n " , `\n` ) + `\n"}` )
@@ -866,13 +868,16 @@ func Test_Root(t *testing.T) {
866868
867869 body , err := io .ReadAll (res .Body )
868870 res .Body .Close ()
871+ fmt .Println ("body:" , string (body ))
869872 if err != nil {
870873 t .Errorf ("caHandler.Root unexpected error = %v" , err )
871874 }
872875 if tt .statusCode == 200 {
873876 if ! bytes .Equal (bytes .TrimSpace (body ), expected ) {
874877 t .Errorf ("caHandler.Root Body = %s, wants %s" , body , expected )
875878 }
879+ } else {
880+ require .Contains (t , string (body ), tt .expectedMsg )
876881 }
877882 })
878883 }
0 commit comments