forked from apache/camel-k
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trait): leverage ConfigMap binary data for resources
* Any binary data will be using BinaryData ConfiMap instead of Data. We let the cluster to encode/decode the resource * Any text resource will be still using the Data (plain) ConfigMap * The `compression` feature can be run both on binary and text resources, providing a base64 encoded file. * Added unit test to check all the possible scenarios Close apache#1946, close apache#1881
- Loading branch information
Showing
8 changed files
with
344 additions
and
86 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
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
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,99 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You 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 cmd | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRawContentFileMissing(t *testing.T) { | ||
_, _, err := loadRawContent("dsadas") | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestRawBinaryContentType(t *testing.T) { | ||
var tmpFile *os.File | ||
var err error | ||
if tmpFile, err = ioutil.TempFile("", "camel-k-*.json"); err != nil { | ||
t.Error(err) | ||
} | ||
assert.Nil(t, tmpFile.Close()) | ||
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte{1, 2, 3, 4, 5, 6}, 0644)) | ||
|
||
data, contentType, err := loadRawContent(tmpFile.Name()) | ||
assert.Nil(t, err) | ||
assert.Equal(t, []byte{1, 2, 3, 4, 5, 6}, data) | ||
assert.True(t, isBinary(contentType)) | ||
} | ||
|
||
func TestRawApplicationContentType(t *testing.T) { | ||
var tmpFile *os.File | ||
var err error | ||
if tmpFile, err = ioutil.TempFile("", "camel-k-*.json"); err != nil { | ||
t.Error(err) | ||
} | ||
assert.Nil(t, tmpFile.Close()) | ||
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0644)) | ||
|
||
data, contentType, err := loadRawContent(tmpFile.Name()) | ||
assert.Nil(t, err) | ||
assert.Equal(t, `{"hello":"world"}`, string(data)) | ||
assert.False(t, isBinary(contentType)) | ||
} | ||
|
||
func TestTextContentType(t *testing.T) { | ||
var tmpFile *os.File | ||
var err error | ||
if tmpFile, err = ioutil.TempFile("", "camel-k-*.json"); err != nil { | ||
t.Error(err) | ||
} | ||
assert.Nil(t, tmpFile.Close()) | ||
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0644)) | ||
|
||
data, contentType, compressed, err := loadTextContent(tmpFile.Name(), false) | ||
assert.Nil(t, err) | ||
assert.Equal(t, `{"hello":"world"}`, string(data)) | ||
assert.False(t, isBinary(contentType)) | ||
assert.False(t, compressed) | ||
} | ||
|
||
func TestTextCompressed(t *testing.T) { | ||
var tmpFile *os.File | ||
var err error | ||
if tmpFile, err = ioutil.TempFile("", "camel-k-*.json"); err != nil { | ||
t.Error(err) | ||
} | ||
assert.Nil(t, tmpFile.Close()) | ||
assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0644)) | ||
|
||
data, contentType, compressed, err := loadTextContent(tmpFile.Name(), true) | ||
assert.Nil(t, err) | ||
assert.NotEqual(t, `{"hello":"world"}`, string(data)) | ||
assert.False(t, isBinary(contentType)) | ||
assert.True(t, compressed) | ||
} | ||
|
||
func TestIsBinary(t *testing.T) { | ||
assert.True(t, isBinary("image/jpeg")) | ||
assert.True(t, isBinary("application/zip")) | ||
assert.False(t, isBinary("text/plain")) | ||
} |
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
Oops, something went wrong.