@@ -433,65 +433,61 @@ func TestQueryMechanisms(t *testing.T) {
433433 })
434434}
435435
436- // A caller supplies the callback URL on every Render , so run the whole
437- // corpus through one call : no guide may keep the key, and a guide that
438- // never carried it must come back byte-identical.
436+ // A caller supplies the callback URL on every render , so run both
437+ // renderers over the whole corpus : no output may keep the key, and content
438+ // that never carried it must come back byte-identical.
439439func TestRenderSubstitutesEveryKey (t * testing.T ) {
440440 const callback = "https://app.example.com/oauth/callback"
441441 key := []byte (canonicalCallbackKey )
442+ vars := guides.Vars {OAuthCallbackURL : callback }
442443 substituted := 0
443- for _ , g := range guides .Guides () {
444- hadKey := bytes .Contains (g .External , key ) || bytes .Contains (g .Speakeasy , key )
445- out := g .Render (guides.Vars {OAuthCallbackURL : callback })
446-
447- if bytes .Contains (out .External , key ) || bytes .Contains (out .Speakeasy , key ) {
448- t .Errorf ("%s: content still carries the key after Render" , g .Slug )
444+ check := func (slug guides.GuideSlug , field string , raw , out []byte ) {
445+ if bytes .Contains (out , key ) {
446+ t .Errorf ("%s %s: output still carries the key" , slug , field )
449447 }
450- if ! bytes .Equal (out .Meta , g .Meta ) {
451- t .Errorf ("%s: Render must not touch Meta" , g .Slug )
452- }
453-
454- if ! hadKey {
455- if ! bytes .Equal (out .External , g .External ) || ! bytes .Equal (out .Speakeasy , g .Speakeasy ) {
456- t .Errorf ("%s: Render changed a guide that carries no key" , g .Slug )
448+ if ! bytes .Contains (raw , key ) {
449+ if ! bytes .Equal (out , raw ) {
450+ t .Errorf ("%s %s: content with no key changed" , slug , field )
457451 }
458- continue
452+ return
459453 }
460454 substituted ++
461- if ! bytes .Contains (out .External , []byte (callback )) &&
462- ! bytes .Contains (out .Speakeasy , []byte (callback )) {
463- t .Errorf ("%s: Render substituted nothing" , g .Slug )
455+ if ! bytes .Contains (out , []byte (callback )) {
456+ t .Errorf ("%s %s: substituted nothing" , slug , field )
464457 }
465458 }
459+ for _ , g := range guides .Guides () {
460+ check (g .Slug , "External" , g .External , g .RenderExternal (vars ))
461+ check (g .Slug , "Speakeasy" , g .Speakeasy , g .RenderSpeakeasy (vars ))
462+ }
466463 if substituted == 0 {
467464 t .Fatal ("no guide carries the key; the matrix would be vacuous" )
468465 }
469466}
470467
471- // A missing value must degrade to the unrendered guide , never to a blank
468+ // A missing value must degrade to the unrendered content , never to a blank
472469// where the URL belongs.
473470func TestRenderLeavesKeyWhenValueEmpty (t * testing.T ) {
474471 g , ok := guides .Lookup ("intercom" )
475472 if ! ok {
476473 t .Fatal ("intercom missing" )
477474 }
478- out := g .Render (guides.Vars {})
479- if ! bytes .Contains (out .External , []byte (canonicalCallbackKey )) {
475+ if ! bytes .Contains (g .RenderExternal (guides.Vars {}), []byte (canonicalCallbackKey )) {
480476 t .Error ("empty Vars must leave the template key in place" )
481477 }
482478}
483479
484- // The embedded bytes back every future Lookup, so rendering one copy must
485- // not reach them. A caller that renders per request depends on this.
480+ // The embedded bytes back every future Lookup, so rendering must not reach
481+ // them. A caller that renders per request depends on this.
486482func TestRenderDoesNotDisturbEmbeddedContent (t * testing.T ) {
487483 g , ok := guides .Lookup ("intercom" )
488484 if ! ok {
489485 t .Fatal ("intercom missing" )
490486 }
491487 before := string (g .External )
492- _ = g .Render (guides.Vars {OAuthCallbackURL : "https://app.example.com/cb" })
488+ _ = g .RenderExternal (guides.Vars {OAuthCallbackURL : "https://app.example.com/cb" })
493489 if string (g .External ) != before {
494- t .Error ("Render mutated the Guide it was called on" )
490+ t .Error ("a renderer changed the Guide it was called on" )
495491 }
496492 again , ok := guides .Lookup ("intercom" )
497493 if ! ok {
0 commit comments