mirror of https://github.com/kubernetes/kops.git
Merge pull request #4648 from justinsb/keypair_integration_test_print_diffs
keypair integration test: print diffs
This commit is contained in:
commit
698c79f28c
|
|
@ -5,6 +5,7 @@ go_test(
|
||||||
srcs = ["keypair_test.go"],
|
srcs = ["keypair_test.go"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/apis/kops:go_default_library",
|
"//pkg/apis/kops:go_default_library",
|
||||||
|
"//pkg/diff:go_default_library",
|
||||||
"//upup/pkg/fi:go_default_library",
|
"//upup/pkg/fi:go_default_library",
|
||||||
"//upup/pkg/fi/fitasks:go_default_library",
|
"//upup/pkg/fi/fitasks:go_default_library",
|
||||||
"//util/pkg/vfs:go_default_library",
|
"//util/pkg/vfs:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ limitations under the License.
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -40,6 +39,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
"k8s.io/kops/pkg/diff"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/fitasks"
|
"k8s.io/kops/upup/pkg/fi/fitasks"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
|
@ -139,7 +139,7 @@ func TestKeypairUpgrade(t *testing.T) {
|
||||||
checkPaths(t, basedir, expected)
|
checkPaths(t, basedir, expected)
|
||||||
|
|
||||||
// Save the contents of those files
|
// Save the contents of those files
|
||||||
contents := make(map[string][]byte)
|
contents := make(map[string]string)
|
||||||
for _, k := range expected {
|
for _, k := range expected {
|
||||||
p, err := vfs.Context.BuildVfsPath(k)
|
p, err := vfs.Context.BuildVfsPath(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -149,7 +149,7 @@ func TestKeypairUpgrade(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading vfs path: %v", err)
|
t.Fatalf("error reading vfs path: %v", err)
|
||||||
}
|
}
|
||||||
contents[k] = b
|
contents[k] = string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("verifying that rerunning tasks does not change keys")
|
t.Logf("verifying that rerunning tasks does not change keys")
|
||||||
|
|
@ -214,19 +214,19 @@ func checkPaths(t *testing.T, basedir vfs.Path, expected []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkPaths verifies that the files and their contents in the tree rooted at basedir are exactly as expected
|
// checkPaths verifies that the files and their contents in the tree rooted at basedir are exactly as expected
|
||||||
func checkContents(t *testing.T, basedir vfs.Path, expected map[string][]byte) {
|
func checkContents(t *testing.T, basedir vfs.Path, expected map[string]string) {
|
||||||
paths, err := basedir.ReadTree()
|
paths, err := basedir.ReadTree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("ReadTree failed: %v", err)
|
t.Errorf("ReadTree failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := make(map[string][]byte)
|
actual := make(map[string]string)
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
b, err := p.ReadFile()
|
b, err := p.ReadFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error reading vfs path: %v", err)
|
t.Fatalf("error reading vfs path %q: %v", p, err)
|
||||||
}
|
}
|
||||||
actual[p.Path()] = b
|
actual[p.Path()] = string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
var actualKeys []string
|
var actualKeys []string
|
||||||
|
|
@ -245,10 +245,10 @@ func checkContents(t *testing.T, basedir vfs.Path, expected map[string][]byte) {
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
for k := range actual {
|
for k := range actual {
|
||||||
if !bytes.Equal(actual[k], expected[k]) {
|
if actual[k] != expected[k] {
|
||||||
t.Logf("mismatch on key %q", k)
|
t.Errorf("mismatch on key %q", k)
|
||||||
|
t.Errorf("diff: %s", diff.FormatDiff(actual[k], expected[k]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Fatalf("unexpected path contents: %v", actual)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue