示例#1
0
func TestSavePodToFile(t *testing.T) {
	pod := volume.NewPersistentVolumeRecyclerPodTemplate()

	// sets all default values on a pod for equality comparison after decoding from file
	encoded, err := latest.GroupOrDie("").Codec.Encode(pod)
	latest.GroupOrDie("").Codec.DecodeInto(encoded, pod)

	path := fmt.Sprintf("/tmp/kube-io-test-%s", uuid.New())
	defer os.Remove(path)

	if err := io.SavePodToFile(pod, path, 777); err != nil {
		t.Fatalf("failed to save pod to file: %v", err)
	}

	podFromFile, err := io.LoadPodFromFile(path)
	if err != nil {
		t.Fatalf("failed to load pod from file: %v", err)
	}
	if !api.Semantic.DeepEqual(pod, podFromFile) {
		t.Errorf("\nexpected %#v\ngot	%#v\n", pod, podFromFile)
	}
}
示例#2
0
func TestSavePodToFile(t *testing.T) {
	pod := volume.NewPersistentVolumeRecyclerPodTemplate()

	// sets all default values on a pod for equality comparison after decoding from file
	codec := api.Codecs.LegacyCodec(registered.GroupOrDie(api.GroupName).GroupVersion)
	encoded, err := runtime.Encode(codec, pod)
	runtime.DecodeInto(codec, encoded, pod)

	tmpDir := utiltesting.MkTmpdirOrDie("kube-io-test")
	defer os.RemoveAll(tmpDir)
	path := fmt.Sprintf("/%s/kube-io-test-%s", tmpDir, uuid.New())

	if err := io.SavePodToFile(pod, path, 777); err != nil {
		t.Fatalf("failed to save pod to file: %v", err)
	}

	podFromFile, err := io.LoadPodFromFile(path)
	if err != nil {
		t.Fatalf("failed to load pod from file: %v", err)
	}
	if !api.Semantic.DeepEqual(pod, podFromFile) {
		t.Errorf("\nexpected %#v\ngot	%#v\n", pod, podFromFile)
	}
}