@@ -835,20 +835,22 @@ func Test_Health(t *testing.T) {
835
835
}
836
836
837
837
func Test_Root (t * testing.T ) {
838
+ const sha = "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36"
838
839
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
843
845
}{
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 },
846
848
}
847
849
848
850
// Request with chi context
849
851
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 )
852
854
req = req .WithContext (context .WithValue (context .Background (), chi .RouteCtxKey , chiCtx ))
853
855
854
856
expected := []byte (`{"ca":"` + strings .ReplaceAll (rootPEM , "\n " , `\n` ) + `\n"}` )
@@ -866,13 +868,16 @@ func Test_Root(t *testing.T) {
866
868
867
869
body , err := io .ReadAll (res .Body )
868
870
res .Body .Close ()
871
+ fmt .Println ("body:" , string (body ))
869
872
if err != nil {
870
873
t .Errorf ("caHandler.Root unexpected error = %v" , err )
871
874
}
872
875
if tt .statusCode == 200 {
873
876
if ! bytes .Equal (bytes .TrimSpace (body ), expected ) {
874
877
t .Errorf ("caHandler.Root Body = %s, wants %s" , body , expected )
875
878
}
879
+ } else {
880
+ require .Contains (t , string (body ), tt .expectedMsg )
876
881
}
877
882
})
878
883
}
0 commit comments