Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): create dir path before file write #30

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/vela-kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,11 @@ func (c *Config) Write() error {
// create full path for .kube/config file
path := filepath.Join(home, ".kube/config")

// send Filesystem call to create directory path for .kube/config file
err = a.Fs.MkdirAll(filepath.Dir(path), 0777)
if err != nil {
return err
}

return a.WriteFile(path, []byte(c.File), 0600)
}
19 changes: 19 additions & 0 deletions cmd/vela-kubernetes/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ func TestKubernetes_Config_Write(t *testing.T) {
}
}

func TestKubernetes_Config_Write_Error(t *testing.T) {
// setup filesystem
appFS = afero.NewReadOnlyFs(afero.NewMemMapFs())

// setup types
c := &Config{
Action: "apply",
File: "file",
Cluster: "cluster",
Context: "context",
Namespace: "namespace",
}

err := c.Write()
if err == nil {
t.Errorf("Write should have returned err")
}
}

func TestKubernetes_Config_Write_NoFile(t *testing.T) {
// setup filesystem
appFS = afero.NewMemMapFs()
Expand Down