Skip to content

Commit 05925a1

Browse files
authored
Remove dead code and test for Realpath. (#895)
Related issue: 894 while investigating test coverage for changes to installed symlinks this was found to be unused
1 parent e0fe5e3 commit 05925a1

2 files changed

Lines changed: 0 additions & 66 deletions

File tree

internal/environment/environment.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,3 @@ func (p Paths) PluginInstallReceiptPath(plugin string) string {
109109
func (p Paths) PluginVersionInstallPath(plugin, version string) string {
110110
return filepath.Join(p.InstallPath(), plugin, version)
111111
}
112-
113-
// Realpath evaluates symbolic links. If the path is not a symbolic link, it
114-
// returns the cleaned path. Symbolic links with relative paths return error.
115-
func Realpath(path string) (string, error) {
116-
s, err := os.Lstat(path)
117-
if err != nil {
118-
return "", errors.Wrapf(err, "failed to stat the currently executed path (%q)", path)
119-
}
120-
121-
if s.Mode()&os.ModeSymlink != 0 {
122-
if path, err = os.Readlink(path); err != nil {
123-
return "", errors.Wrap(err, "failed to resolve the symlink of the currently executed version")
124-
}
125-
if !filepath.IsAbs(path) {
126-
return "", errors.Errorf("symbolic link is relative (%s)", path)
127-
}
128-
}
129-
return filepath.Clean(path), nil
130-
}

internal/environment/environment_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
package environment
1616

1717
import (
18-
"os"
1918
"path/filepath"
2019
"strings"
2120
"testing"
2221

2322
"k8s.io/client-go/util/homedir"
2423

25-
"sigs.k8s.io/krew/internal/testutil"
2624
"sigs.k8s.io/krew/pkg/constants"
2725
)
2826

@@ -78,48 +76,3 @@ func TestPaths(t *testing.T) {
7876
t.Errorf("PluginInstallReceiptPath()=%s; expected suffix 'receipts/my-plugin.yaml'", got)
7977
}
8078
}
81-
82-
func TestRealpath(t *testing.T) {
83-
tmpDir := testutil.NewTempDir(t)
84-
85-
// create regular file
86-
tmpDir.Write("regular-file", nil)
87-
88-
// create absolute symlink
89-
orig := filepath.Clean(os.TempDir())
90-
if err := os.Symlink(orig, filepath.Join(tmpDir.Root(), "symbolic-link-abs")); err != nil {
91-
t.Fatal(err)
92-
}
93-
94-
// create relative symlink
95-
if err := os.Symlink("./another-file", filepath.Join(tmpDir.Root(), "symbolic-link-rel")); err != nil {
96-
t.Fatal(err)
97-
}
98-
99-
tests := []struct {
100-
name string
101-
in string
102-
want string
103-
wantErr bool
104-
}{
105-
{"file not exists", tmpDir.Path("/not/exists"), "", true},
106-
{"directory", tmpDir.Root(), tmpDir.Root(), false},
107-
{"regular file", tmpDir.Path("regular-file"), tmpDir.Path("regular-file"), false},
108-
{"directory unclean", tmpDir.Path("foo/.."), tmpDir.Root(), false},
109-
{"regular file unclean", tmpDir.Path("regular-file/foo/.."), tmpDir.Path("regular-file"), false},
110-
{"relative symbolic link", tmpDir.Path("symbolic-link-rel"), "", true},
111-
{"absolute symbolic link", tmpDir.Path("symbolic-link-abs"), orig, false},
112-
}
113-
for _, tt := range tests {
114-
t.Run(tt.name, func(t *testing.T) {
115-
got, err := Realpath(tt.in)
116-
if (err != nil) != tt.wantErr {
117-
t.Errorf("Realpath(%s) error = %v, wantErr %v", tt.in, err, tt.wantErr)
118-
return
119-
}
120-
if got != tt.want {
121-
t.Errorf("Realpath(%s) = %v, want %v", tt.in, got, tt.want)
122-
}
123-
})
124-
}
125-
}

0 commit comments

Comments
 (0)