package gemini_test import ( "bufio" "reflect" "strings" "testing" "source.community/ckaznocha/gemini" ) func TestReadRequest(t *testing.T) { t.Parallel() type args struct { b *bufio.Reader } tests := []struct { args args want *gemini.Request name string wantErr bool }{ // { // name: "", // args: args{ // b: bufio.NewReader(strings.NewReader("gemini://example.com/\r\n")), // }, // want: &gemini.Request{ // URI: &gemini.URI{ // Query: map[string][]string{}, // Host: "example.com", // Port: "", // Path: "/", // Fragment: "", // RawQuery: "", // }, // RemoteAddr: "", // Subject: nil, // }, // wantErr: false, // }, { name: "malformed request errors", args: args{ b: bufio.NewReader(strings.NewReader("gemini://example.com/")), }, wantErr: true, }, { name: "request too long errors", args: args{ b: bufio.NewReader(strings.NewReader("gemini://example.com/" + strings.Repeat("a", 1024) + "\r\n")), }, wantErr: true, }, { name: "invalid URI errors", args: args{ b: bufio.NewReader(strings.NewReader("/foo\r\n")), }, wantErr: true, }, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() got, err := gemini.ReadRequest(tt.args.b) if (err != nil) != tt.wantErr { t.Errorf("ReadRequest(%v) error = %v, wantErr %v", tt.args.b, err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { t.Errorf("ReadRequest(%v) = %v, want %v", tt.args.b, got, tt.want) } }) } }