diff options
Diffstat (limited to 'gemini_test.go')
-rw-r--r-- | gemini_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gemini_test.go b/gemini_test.go new file mode 100644 index 0000000..e029c04 --- /dev/null +++ b/gemini_test.go @@ -0,0 +1,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) + } + } +} |