-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libpod): support kube play tar content-type (#24015)
feat(libpod): support kube play tar content-type Signed-off-by: fixomatic-ctrl <[email protected]>
- Loading branch information
1 parent
514d25d
commit 1dd90db
Showing
4 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1dd90db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
podman-next COPR build failed. @containers/packit-build please check.