From 064b1b304a0b11766e682fe9fa8929df7977fb27 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Thu, 12 Jan 2023 09:20:43 -0700 Subject: test file rename --- gemini/client_server_test.go | 65 -------------------------------------------- gemini/roundtrip_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 65 deletions(-) delete mode 100644 gemini/client_server_test.go create mode 100644 gemini/roundtrip_test.go diff --git a/gemini/client_server_test.go b/gemini/client_server_test.go deleted file mode 100644 index 5dd61f1..0000000 --- a/gemini/client_server_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package gemini_test - -import ( - "bytes" - "context" - "crypto/tls" - "fmt" - "io" - "net/url" - "testing" - - "tildegit.org/tjp/gus/gemini" -) - -func TestRoundTrip(t *testing.T) { - tlsConf, err := gemini.FileTLS("./testdata/server.crt", "./testdata/server.key") - if err != nil { - t.Fatalf("FileTLS(): %s", err.Error()) - } - - handler := func(ctx context.Context, req *gemini.Request) *gemini.Response { - return gemini.Success("text/gemini", bytes.NewBufferString("you've found my page")) - } - - server, err := gemini.NewServer(context.Background(), tlsConf, "tcp", "127.0.0.1:0", handler) - if err != nil { - t.Fatalf("NewServer(): %s", err.Error()) - } - - go server.Serve() - defer server.Close() - - u, err := url.Parse(fmt.Sprintf("gemini://%s/test", server.Address())) - if err != nil { - t.Fatalf("url.Parse: %s", err.Error()) - } - - cli := gemini.NewClient(testClientTLS()) - response, err := cli.RoundTrip(&gemini.Request{URL: u}) - if err != nil { - t.Fatalf("RoundTrip(): %s", err.Error()) - } - - if response.Status != gemini.StatusSuccess { - t.Errorf("response status: expected %d, got %d", gemini.StatusSuccess, response.Status) - } - if response.Meta != "text/gemini" { - t.Errorf("response meta: expected \"text/gemini\", got %q", response.Meta) - } - - if response.Body == nil { - t.Fatal("succcess response has nil body") - } - body, err := io.ReadAll(response.Body) - if err != nil { - t.Fatalf("ReadAll: %s", err.Error()) - } - if string(body) != "you've found my page" { - t.Errorf("response body: expected \"you've found my page\", got %q", string(body)) - } -} - -func testClientTLS() *tls.Config { - return &tls.Config{InsecureSkipVerify: true} -} diff --git a/gemini/roundtrip_test.go b/gemini/roundtrip_test.go new file mode 100644 index 0000000..5dd61f1 --- /dev/null +++ b/gemini/roundtrip_test.go @@ -0,0 +1,65 @@ +package gemini_test + +import ( + "bytes" + "context" + "crypto/tls" + "fmt" + "io" + "net/url" + "testing" + + "tildegit.org/tjp/gus/gemini" +) + +func TestRoundTrip(t *testing.T) { + tlsConf, err := gemini.FileTLS("./testdata/server.crt", "./testdata/server.key") + if err != nil { + t.Fatalf("FileTLS(): %s", err.Error()) + } + + handler := func(ctx context.Context, req *gemini.Request) *gemini.Response { + return gemini.Success("text/gemini", bytes.NewBufferString("you've found my page")) + } + + server, err := gemini.NewServer(context.Background(), tlsConf, "tcp", "127.0.0.1:0", handler) + if err != nil { + t.Fatalf("NewServer(): %s", err.Error()) + } + + go server.Serve() + defer server.Close() + + u, err := url.Parse(fmt.Sprintf("gemini://%s/test", server.Address())) + if err != nil { + t.Fatalf("url.Parse: %s", err.Error()) + } + + cli := gemini.NewClient(testClientTLS()) + response, err := cli.RoundTrip(&gemini.Request{URL: u}) + if err != nil { + t.Fatalf("RoundTrip(): %s", err.Error()) + } + + if response.Status != gemini.StatusSuccess { + t.Errorf("response status: expected %d, got %d", gemini.StatusSuccess, response.Status) + } + if response.Meta != "text/gemini" { + t.Errorf("response meta: expected \"text/gemini\", got %q", response.Meta) + } + + if response.Body == nil { + t.Fatal("succcess response has nil body") + } + body, err := io.ReadAll(response.Body) + if err != nil { + t.Fatalf("ReadAll: %s", err.Error()) + } + if string(body) != "you've found my page" { + t.Errorf("response body: expected \"you've found my page\", got %q", string(body)) + } +} + +func testClientTLS() *tls.Config { + return &tls.Config{InsecureSkipVerify: true} +} -- cgit v1.2.3