💾 Archived View for source.community › ckaznocha › gemini › raw › main › handler_test.go captured on 2021-12-17 at 13:26:06.

View Raw

More Information

-=-=-=-=-=-=-

package gemini_test

import (
	"context"
	"fmt"
	"testing"

	"source.community/ckaznocha/gemini"
	"source.community/ckaznocha/gemini/geminitest"
)

func TestHandlerFunc_ServeGemini(t *testing.T) {
	t.Parallel()

	type args struct {
		r *gemini.Request
	}

	tests := []struct {
		name string
		f    gemini.HandlerFunc
		args args
		want string
	}{
		{
			name: "",
			f: func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
				fmt.Fprint(w.Success(ctx, ""), "Hello, Gemini!")
			},
			args: args{
				r: geminitest.NewRequest("gemini://example.com/"),
			},
			want: "Hello, Gemini!",
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			recorder := geminitest.NewResponseRecorder()
			tt.f.ServeGemini(context.Background(), recorder, tt.args.r)

			if recorder.Body.String() != tt.want {
				t.Errorf("HandlerFunc_ServeGemini() got = %v, want %v", recorder.Body.String(), tt.want)
			}
		})
	}
}