MCPcopy
hub / github.com/kubernetes/kubectl / TestDefaultConsumeRequest

Function TestDefaultConsumeRequest

pkg/cmd/logs/logs_test.go:873–938  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

871}
872
873func TestDefaultConsumeRequest(t *testing.T) {
874 tests := []struct {
875 name string
876 request restclient.ResponseWrapper
877 expectedErr string
878 expectedOut string
879 }{
880 {
881 name: "error from request stream",
882 request: &responseWrapperMock{
883 err: errors.New("err from the stream"),
884 },
885 expectedErr: "err from the stream",
886 },
887 {
888 name: "error while reading",
889 request: &responseWrapperMock{
890 data: iotest.TimeoutReader(strings.NewReader("Some data")),
891 },
892 expectedErr: iotest.ErrTimeout.Error(),
893 expectedOut: "Some data",
894 },
895 {
896 name: "read with empty string",
897 request: &responseWrapperMock{
898 data: strings.NewReader(""),
899 },
900 expectedOut: "",
901 },
902 {
903 name: "read without new lines",
904 request: &responseWrapperMock{
905 data: strings.NewReader("some string without a new line"),
906 },
907 expectedOut: "some string without a new line",
908 },
909 {
910 name: "read with newlines in the middle",
911 request: &responseWrapperMock{
912 data: strings.NewReader("foo\nbar"),
913 },
914 expectedOut: "foo\nbar",
915 },
916 {
917 name: "read with newline at the end",
918 request: &responseWrapperMock{
919 data: strings.NewReader("foo\n"),
920 },
921 expectedOut: "foo\n",
922 },
923 }
924 for _, test := range tests {
925 t.Run(test.name, func(t *testing.T) {
926 buf := &bytes.Buffer{}
927 err := DefaultConsumeRequest(context.TODO(), test.request, buf)
928
929 if err != nil && !strings.Contains(err.Error(), test.expectedErr) {
930 t.Errorf("%s: expected to find:\n\t%s\nfound:\n\t%s\n", test.name, test.expectedErr, err.Error())

Callers

nothing calls this directly

Calls 4

DefaultConsumeRequestFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…