forked from vmware-tanzu/velero
-
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.
Reduces ~140 indirect imports for plugin/framework importers (vmware-…
…tanzu#8208) * Avoid plugin framework importers from needing cloud provider imports Signed-off-by: Tiger Kaovilai <[email protected]>
- Loading branch information
Showing
19 changed files
with
230 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reduces indirect imports for plugin/framework importers |
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
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,53 @@ | ||
package install | ||
|
||
import ( | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// test that this package do not import cloud provider | ||
|
||
// Prevent https://github.com/vmware-tanzu/velero/issues/8207 and https://github.com/vmware-tanzu/velero/issues/8157 | ||
func TestPkgImportNoCloudProvider(t *testing.T) { | ||
_, filename, _, ok := runtime.Caller(0) | ||
if !ok { | ||
t.Fatalf("No caller information") | ||
} | ||
t.Logf("Current test file path: %s", filename) | ||
t.Logf("Current test directory: %s", filepath.Dir(filename)) // should be this package name | ||
// go list -f {{.Deps}} ./<path-to-this-package-dir> | ||
cmd := exec.Command( | ||
"go", | ||
"list", | ||
"-f", | ||
"{{.Deps}}", | ||
".", | ||
) | ||
// set cmd.Dir to this package even if executed from different dir | ||
cmd.Dir = filepath.Dir(filename) | ||
output, err := cmd.Output() | ||
require.NoError(t, err) | ||
// split dep by line, replace space with newline | ||
deps := strings.ReplaceAll(string(output), " ", "\n") | ||
require.NotEmpty(t, deps) | ||
// ignore k8s.io | ||
k8sio, err := regexp.Compile("^k8s.io") | ||
require.NoError(t, err) | ||
cloudProvider, err := regexp.Compile("aws|cloud.google.com|azure") | ||
require.NoError(t, err) | ||
cloudProviderDeps := []string{} | ||
for _, dep := range strings.Split(deps, "\n") { | ||
if !k8sio.MatchString(dep) { | ||
if cloudProvider.MatchString(dep) { | ||
cloudProviderDeps = append(cloudProviderDeps, dep) | ||
} | ||
} | ||
} | ||
require.Empty(t, cloudProviderDeps) | ||
} |
Oops, something went wrong.