aboutsummaryrefslogtreecommitdiff
path: root/gemini_test.go
blob: e029c046c9f5350ae583e1e5eba0e4fda737bdf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"bytes"
	"strconv"
	"testing"
)

func TestNewGeminiConn(t *testing.T) {
	tables := []struct {
		url  string
		port int
		host string
	}{
		{"hostname.com", GeminiPort, "hostname.com:" + strconv.Itoa(GeminiPort)},
		{"hostname.com", 1234, "hostname.com:1234"},
	}

	for _, table := range tables {
		conn, err := NewGeminiConn(table.url, table.port)
		if err != nil {
			t.Fatalf("NewGeminiConn error: %s", err.Error())
		}
		if conn.host != table.host {
			t.Fatalf("NewGeminiConn error: wrong hostname %s", conn.host)
		}
	}
}

func TestFormatRequest(t *testing.T) {
	tables := []struct {
		input  string
		output []byte
	}{
		{"hostname.com", []byte("gemini://hostname.com\r\n")},
	}

	for _, table := range tables {
		if !bytes.Equal(FormatRequest(table.input), table.output) {
			t.Fatalf("FormatRequest failed on: %s\n", table.input)
		}
	}
}