This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/components/util: make HelmActionConfig use kubeconfig file content
As part of #608, this commit changes the implementation of HelmActionConfig function to read the content of given kubeconfig file and then use the content to construct Helm's actionConfig. This will make easier changing the function signature to accept content of kubeconfig file in the future changes. Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
- Loading branch information
Showing
2 changed files
with
93 additions
and
3 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,80 @@ | ||
package util_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/kinvolk/lokomotive/pkg/components/util" | ||
) | ||
|
||
const ( | ||
validKubeconfig = ` | ||
apiVersion: v1 | ||
kind: Config | ||
clusters: | ||
- name: admin | ||
cluster: | ||
server: https://nonexistent:6443 | ||
users: | ||
- name: admin | ||
user: | ||
token: "foo.bar" | ||
current-context: admin | ||
contexts: | ||
- name: admin | ||
context: | ||
cluster: admin | ||
user: admin | ||
` | ||
) | ||
|
||
func TestHelmActionConfigFromValidKubeconfigFile(t *testing.T) { | ||
tmpFile, err := ioutil.TempFile("", "lokoctl-tests-") | ||
if err != nil { | ||
t.Fatalf("creating tmp file should succeed, got: %v", err) | ||
} | ||
|
||
defer func() { | ||
if err := os.Remove(tmpFile.Name()); err != nil { | ||
t.Logf("failed to remove tmp file %q: %v", tmpFile.Name(), err) | ||
} | ||
}() | ||
|
||
if _, err := tmpFile.Write([]byte(validKubeconfig)); err != nil { | ||
t.Fatalf("writing to tmp file %q should succeed, got: %v", tmpFile.Name(), err) | ||
} | ||
|
||
if err := tmpFile.Close(); err != nil { | ||
t.Fatalf("closing tmp file %q should succeed, got: %v", tmpFile.Name(), err) | ||
} | ||
|
||
if _, err := util.HelmActionConfig("foo", tmpFile.Name()); err != nil { | ||
t.Fatalf("creating helm action config from valid kubeconfig file should succeed, got: %v", err) | ||
} | ||
} | ||
|
||
func TestHelmActionConfigFromInvalidKubeconfigFile(t *testing.T) { | ||
tmpFile, err := ioutil.TempFile("", "lokoctl-tests-") | ||
if err != nil { | ||
t.Fatalf("creating tmp file should succeed, got: %v", err) | ||
} | ||
|
||
defer func() { | ||
if err := os.Remove(tmpFile.Name()); err != nil { | ||
t.Logf("failed to remove tmp file %q: %v", tmpFile.Name(), err) | ||
} | ||
}() | ||
|
||
if _, err := tmpFile.Write([]byte("foo")); err != nil { | ||
t.Fatalf("writing to tmp file %q should succeed, got: %v", tmpFile.Name(), err) | ||
} | ||
|
||
if err := tmpFile.Close(); err != nil { | ||
t.Fatalf("closing tmp file %q should succeed, got: %v", tmpFile.Name(), err) | ||
} | ||
|
||
if _, err := util.HelmActionConfig("foo", tmpFile.Name()); err == nil { | ||
t.Fatalf("creating helm action config from invalid kubeconfig file should fail") | ||
} | ||
} |