github.com/MetalBlockchain/metalgo@v1.11.9/vms/rpcchainvm/ghttp/http_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package ghttp 5 6 import ( 7 "net/http/httptest" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 httppb "github.com/MetalBlockchain/metalgo/proto/pb/http" 13 ) 14 15 func TestConvertWriteResponse(t *testing.T) { 16 scenerios := map[string]struct { 17 resp *httppb.HandleSimpleHTTPResponse 18 }{ 19 "empty response": { 20 resp: &httppb.HandleSimpleHTTPResponse{}, 21 }, 22 "response header value empty": { 23 resp: &httppb.HandleSimpleHTTPResponse{ 24 Code: 500, 25 Body: []byte("foo"), 26 Headers: []*httppb.Element{ 27 { 28 Key: "foo", 29 }, 30 }, 31 }, 32 }, 33 "response header key empty": { 34 resp: &httppb.HandleSimpleHTTPResponse{ 35 Code: 200, 36 Body: []byte("foo"), 37 Headers: []*httppb.Element{ 38 { 39 Values: []string{"foo"}, 40 }, 41 }, 42 }, 43 }, 44 } 45 for testName, scenerio := range scenerios { 46 t.Run(testName, func(t *testing.T) { 47 w := httptest.NewRecorder() 48 require.NoError(t, convertWriteResponse(w, scenerio.resp)) 49 }) 50 } 51 }