-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API to manage plugin owned settings (#99)
- Loading branch information
1 parent
39c403b
commit 923c4c1
Showing
4 changed files
with
84 additions
and
0 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,34 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
// PluginsBaseDir is the name of the plugins owned base directory in which plugin owned settings is stored. | ||
PluginsBaseDir = "plugins" | ||
) | ||
|
||
// GetTanzuPluginConfigDir Retrieve the tanzu configuration directory that can be used by the plugins to // create a plugin specific directory to manage plugin owned configurations. | ||
// .config/tanzu/plugins | ||
func GetTanzuPluginConfigDir() (string, error) { | ||
// Fetch the base tanzu config directory | ||
tanzuDir, err := LocalDir() | ||
if err != nil { | ||
return "", errors.Wrap(err, "could not find local tanzu dir for OS") | ||
} | ||
|
||
// Create plugins directory in tanzu config | ||
pluginsBaseDir := filepath.Join(tanzuDir, PluginsBaseDir) | ||
if err := os.MkdirAll(pluginsBaseDir, 0755); err != nil { | ||
return "", errors.Wrap(err, "could not make local tanzu plugins directory") | ||
} | ||
|
||
return pluginsBaseDir, nil | ||
} |
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,30 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetTanzuPluginConfigDir(t *testing.T) { | ||
// setup | ||
func() { | ||
LocalDirName = ".config2/tanzu" | ||
}() | ||
defer func() { | ||
cleanupDir(LocalDirName) | ||
}() | ||
|
||
expectedPath := ".config2/tanzu/plugins" | ||
|
||
dir, err := GetTanzuPluginConfigDir() | ||
|
||
require.NoError(t, err, "Expected no error from GetTanzuPluginConfigDir") | ||
assert.NotEmpty(t, dir, "Expected a non-empty directory path") | ||
|
||
assert.Contains(t, dir, expectedPath) | ||
} |
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