File: kube_test.go

package info (click to toggle)
podman 5.4.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,124 kB
  • sloc: sh: 6,119; perl: 2,710; python: 2,258; ansic: 1,556; makefile: 1,022; xml: 121; ruby: 42; awk: 12; csh: 8
file content (70 lines) | stat: -rw-r--r-- 1,772 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//go:build !remote

package libpod

import (
	"io"
	"net/http"
	"strings"
	"testing"

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

func TestExtractPlayReader(t *testing.T) {
	// Setup temporary directory for testing purposes
	tempDir := t.TempDir()

	t.Run("Content-Type not provided - should return body", func(t *testing.T) {
		req := &http.Request{
			Body: io.NopCloser(strings.NewReader("test body content")),
		}

		reader, err := extractPlayReader(tempDir, req)
		assert.NoError(t, err)

		// Read from the returned reader
		data, err := io.ReadAll(reader)
		assert.NoError(t, err)
		assert.Equal(t, "test body content", string(data))
	})

	t.Run("Supported content types (json/yaml/text) - should return body", func(t *testing.T) {
		supportedTypes := []string{
			"application/json",
			"application/yaml",
			"application/text",
			"application/x-yaml",
		}

		for _, contentType := range supportedTypes {
			req := &http.Request{
				Header: map[string][]string{
					"Content-Type": {contentType},
				},
				Body: io.NopCloser(strings.NewReader("test body content")),
			}

			reader, err := extractPlayReader(tempDir, req)
			assert.NoError(t, err)

			// Read from the returned reader
			data, err := io.ReadAll(reader)
			assert.NoError(t, err)
			assert.Equal(t, "test body content", string(data))
		}
	})

	t.Run("Unsupported content type - should return error", func(t *testing.T) {
		req := &http.Request{
			Header: map[string][]string{
				"Content-Type": {"application/unsupported"},
			},
			Body: io.NopCloser(strings.NewReader("test body content")),
		}

		_, err := extractPlayReader(tempDir, req)
		assert.Error(t, err)
		assert.Equal(t, "Content-Type: application/unsupported is not supported. Should be \"application/x-tar\"", err.Error())
	})
}