$20 GRAYBYTE WORDPRESS FILE MANAGER $15

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 147.79.69.54 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/go/pkg/mod/github.com/go-openapi/runtime@v0.26.0/

HOME
Current File : /opt/go/pkg/mod/github.com/go-openapi/runtime@v0.26.0//client_response_test.go
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package runtime

import (
	"bytes"
	"errors"
	"io"
	"io/fs"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

type response struct {
}

func (r response) Code() int {
	return 490
}
func (r response) Message() string {
	return "the message"
}
func (r response) GetHeader(_ string) string {
	return "the header"
}
func (r response) GetHeaders(_ string) []string {
	return []string{"the headers", "the headers2"}
}
func (r response) Body() io.ReadCloser {
	return io.NopCloser(bytes.NewBufferString("the content"))
}

func TestResponseReaderFunc(t *testing.T) {
	var actual struct {
		Header, Message, Body string
		Code                  int
	}
	reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (interface{}, error) {
		b, _ := io.ReadAll(r.Body())
		actual.Body = string(b)
		actual.Code = r.Code()
		actual.Message = r.Message()
		actual.Header = r.GetHeader("blah")
		return actual, nil
	})
	_, _ = reader.ReadResponse(response{}, nil)
	assert.Equal(t, "the content", actual.Body)
	assert.Equal(t, "the message", actual.Message)
	assert.Equal(t, "the header", actual.Header)
	assert.Equal(t, 490, actual.Code)
}

func TestResponseReaderFuncError(t *testing.T) {
	reader := ClientResponseReaderFunc(func(r ClientResponse, _ Consumer) (interface{}, error) {
		_, _ = io.ReadAll(r.Body())
		return nil, NewAPIError("fake", errors.New("writer closed"), 490)
	})
	_, err := reader.ReadResponse(response{}, nil)
	assert.NotNil(t, err)
	assert.True(t, strings.Contains(err.Error(), "writer closed"), err.Error())

	reader = func(r ClientResponse, _ Consumer) (interface{}, error) {
		_, _ = io.ReadAll(r.Body())
		err := &fs.PathError{
			Op:   "write",
			Path: "path/to/fake",
			Err:  fs.ErrClosed,
		}
		return nil, NewAPIError("fake", err, 200)
	}
	_, err = reader.ReadResponse(response{}, nil)
	assert.NotNil(t, err)
	assert.True(t, strings.Contains(err.Error(), "file already closed"), err.Error())

}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
25 Jan 2024 4.43 PM
root / root
0755
.github
--
25 Jan 2024 4.43 PM
root / root
0555
client
--
25 Jan 2024 4.43 PM
root / root
0555
fixtures
--
25 Jan 2024 4.43 PM
root / root
0555
flagext
--
25 Jan 2024 4.43 PM
root / root
0555
hack
--
25 Jan 2024 4.43 PM
root / root
0555
internal
--
25 Jan 2024 4.43 PM
root / root
0555
logger
--
25 Jan 2024 4.43 PM
root / root
0555
middleware
--
25 Jan 2024 4.43 PM
root / root
0555
security
--
25 Jan 2024 4.43 PM
root / root
0555
yamlpc
--
25 Jan 2024 4.43 PM
root / root
0555
.editorconfig
0.526 KB
25 Jan 2024 4.43 PM
root / root
0444
.gitattributes
0.017 KB
25 Jan 2024 4.43 PM
root / root
0444
.gitignore
0.047 KB
25 Jan 2024 4.43 PM
root / root
0444
.golangci.yml
0.699 KB
25 Jan 2024 4.43 PM
root / root
0444
CODE_OF_CONDUCT.md
3.157 KB
25 Jan 2024 4.43 PM
root / root
0444
LICENSE
11.092 KB
25 Jan 2024 4.43 PM
root / root
0444
README.md
0.705 KB
25 Jan 2024 4.43 PM
root / root
0444
authinfo_test.go
1.071 KB
25 Jan 2024 4.43 PM
root / root
0444
bytestream.go
4.137 KB
25 Jan 2024 4.43 PM
root / root
0444
bytestream_test.go
6.246 KB
25 Jan 2024 4.43 PM
root / root
0444
client_auth_info.go
1.16 KB
25 Jan 2024 4.43 PM
root / root
0444
client_operation.go
1.366 KB
25 Jan 2024 4.43 PM
root / root
0444
client_request.go
3.655 KB
25 Jan 2024 4.43 PM
root / root
0444
client_request_test.go
1.113 KB
25 Jan 2024 4.43 PM
root / root
0444
client_response.go
3.201 KB
25 Jan 2024 4.43 PM
root / root
0444
client_response_test.go
2.477 KB
25 Jan 2024 4.43 PM
root / root
0444
constants.go
1.664 KB
25 Jan 2024 4.43 PM
root / root
0444
csv.go
1.865 KB
25 Jan 2024 4.43 PM
root / root
0444
csv_test.go
1.764 KB
25 Jan 2024 4.43 PM
root / root
0444
discard.go
0.329 KB
25 Jan 2024 4.43 PM
root / root
0444
file.go
0.659 KB
25 Jan 2024 4.43 PM
root / root
0444
file_test.go
0.584 KB
25 Jan 2024 4.43 PM
root / root
0444
go.mod
1.254 KB
25 Jan 2024 4.43 PM
root / root
0444
go.sum
19.355 KB
25 Jan 2024 4.43 PM
root / root
0444
headers.go
1.114 KB
25 Jan 2024 4.43 PM
root / root
0444
headers_test.go
2.018 KB
25 Jan 2024 4.43 PM
root / root
0444
interfaces.go
3.99 KB
25 Jan 2024 4.43 PM
root / root
0444
json.go
1.117 KB
25 Jan 2024 4.43 PM
root / root
0444
json_test.go
1.471 KB
25 Jan 2024 4.43 PM
root / root
0444
request.go
3.33 KB
25 Jan 2024 4.43 PM
root / root
0444
request_test.go
5.06 KB
25 Jan 2024 4.43 PM
root / root
0444
statuses.go
2.515 KB
25 Jan 2024 4.43 PM
root / root
0444
text.go
2.821 KB
25 Jan 2024 4.43 PM
root / root
0444
text_test.go
4.952 KB
25 Jan 2024 4.43 PM
root / root
0444
values.go
0.483 KB
25 Jan 2024 4.43 PM
root / root
0444
values_test.go
0.596 KB
25 Jan 2024 4.43 PM
root / root
0444
xml.go
1.038 KB
25 Jan 2024 4.43 PM
root / root
0444
xml_test.go
1.438 KB
25 Jan 2024 4.43 PM
root / root
0444

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF