Skip to content

Commit

Permalink
Assert upgrade by real plugin path instead of plugin hash sum
Browse files Browse the repository at this point in the history
This assumes that the actual plugin path changes from one version to another.
  • Loading branch information
corneliusweig committed Jul 3, 2019
1 parent ccee40d commit e02c949
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions integration_test/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package integrationtest

import (
"crypto/sha256"
"io"
"os"
"path/filepath"
"testing"

"sigs.k8s.io/krew/pkg/constants"
)

func TestKrewUpgrade(t *testing.T) {
Expand All @@ -28,36 +28,30 @@ func TestKrewUpgrade(t *testing.T) {
test, cleanup := NewTest(t)
defer cleanup()

cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

test.WithIndex().
Krew("install", "--manifest", filepath.Join(cwd, "testdata", "konfig.yaml")).
Krew("install", "--manifest", filepath.Join("testdata", validPlugin+constants.ManifestExtension)).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
initialHash := hashFile(t, location)
initialLocation := realLocation(test, validPlugin)

test.Krew("upgrade").RunOrFail()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
eventualHash := hashFile(t, location)
eventualLocation := realLocation(test, validPlugin)

if string(initialHash) == string(eventualHash) {
t.Errorf("Expecting the plugin file to change but was the same.")
if initialLocation == eventualLocation {
t.Errorf("Expecting the plugin path to change but was the same.")
}
}

func hashFile(t *testing.T, path string) []byte {
t.Helper()
hasher := sha256.New()
file, err := os.Open(path)
defer file.Close()
func realLocation(test *ITest, plugin string) string {
test.t.Helper()
linkToPlugin, err := test.LookupExecutable("kubectl-" + plugin)
if err != nil {
t.Fatal(err)
test.t.Fatal(err)
}
if _, err := io.Copy(hasher, file); err != nil {
t.Fatal(err)

realLocation, err := os.Readlink(linkToPlugin)
if err != nil {
test.t.Fatal(err)
}
return hasher.Sum(nil)

return realLocation
}

0 comments on commit e02c949

Please sign in to comment.