-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: base64 encoded KUBECONFIG_CONTENT (#20)
- Loading branch information
1 parent
6dcdf55
commit 52d14e9
Showing
2 changed files
with
52 additions
and
6 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package kubectl | |
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"errors" | ||
"fmt" | ||
"github.com/buildtool/build-tools/pkg" | ||
|
@@ -212,6 +213,35 @@ func TestKubectl_KubeconfigSet(t *testing.T) { | |
k.Cleanup() | ||
} | ||
|
||
func TestKubectl_KubeconfigBase64Set(t *testing.T) { | ||
out := &bytes.Buffer{} | ||
eout := &bytes.Buffer{} | ||
yaml := `contexts: | ||
- context: | ||
cluster: k8s.prod | ||
user: [email protected] | ||
` | ||
defer pkg.SetEnv(envKubeConfigContentBase64, base64.StdEncoding.EncodeToString([]byte(yaml)))() | ||
k := New(&config.Environment{}, out, eout) | ||
|
||
kubeConfigFile := filepath.Join(k.(*kubectl).tempDir, "kubeconfig") | ||
fileContent, err := ioutil.ReadFile(kubeConfigFile) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "contexts:\n- context:\n cluster: k8s.prod\n user: [email protected]\n", string(fileContent)) | ||
assert.Equal(t, kubeConfigFile, k.(*kubectl).args["kubeconfig"]) | ||
k.Cleanup() | ||
} | ||
|
||
func TestKubectl_KubeconfigInvalidBase64Set(t *testing.T) { | ||
out := &bytes.Buffer{} | ||
eout := &bytes.Buffer{} | ||
defer pkg.SetEnv(envKubeConfigContentBase64, "äö")() | ||
k := New(&config.Environment{}, out, eout) | ||
assert.Equal(t, "\x1b[0mFailed to decode content illegal base64 data at input byte 0\x1b[0m\n", eout.String()) | ||
|
||
k.Cleanup() | ||
} | ||
|
||
func TestKubectl_KubeconfigExistingFile(t *testing.T) { | ||
|
||
out := &bytes.Buffer{} | ||
|