func TestHasFieldsType(t *testing.T) {
	var unmarshaled []metav1.ManagedFieldsEntry
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsType: FieldsV1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err != nil {
		t.Fatalf("did not expect decoding error but got: %v", err)
	}

	// Invalid fieldsType V2.
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsType: FieldsV2
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err == nil {
		t.Fatal("Expect decoding error but got none")
	}

	// Missing fieldsType.
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err == nil {
		t.Fatal("Expect decoding error but got none")
	}
}
// TestHasFieldsType makes sure that we fail if we don't have a
// FieldsType set properly.
TestHasFieldsType makes sure that we fail if we don't have a
FieldsType set properly.
// TestHasFieldsType makes sure that we fail if we don ' t have a // FieldsType set properly .
func TestHasFieldsType(t *testing.T) {
	var unmarshaled []metav1.ManagedFieldsEntry
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsType: FieldsV1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err != nil {
		t.Fatalf("did not expect decoding error but got: %v", err)
	}
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsType: FieldsV2
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err == nil {
		t.Fatal("Expect decoding error but got none")
	}
	if err := yaml.Unmarshal([]byte(`- apiVersion: v1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
`), &unmarshaled); err != nil {
		t.Fatalf("did not expect yaml unmarshalling error but got: %v", err)
	}
	if _, err := decodeManagedFields(unmarshaled); err == nil {
		t.Fatal("Expect decoding error but got none")
	}
}
func TestHasFieldsType ( t * testing . T ) { var unmarshaled [ ] metav1 . ManagedFieldsEntry if err := yaml . Unmarshal ( [ ] byte ( `- apiVersion: v1
  fieldsType: FieldsV1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
` ) , & unmarshaled ) ; err != nil { t . Fatalf ( " " , err ) } if _ , err := decodeManagedFields ( unmarshaled ) ; err != nil { t . Fatalf ( " " , err ) } if err := yaml . Unmarshal ( [ ] byte ( `- apiVersion: v1
  fieldsType: FieldsV2
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
` ) , & unmarshaled ) ; err != nil { t . Fatalf ( " " , err ) } if _ , err := decodeManagedFields ( unmarshaled ) ; err == nil { t . Fatal ( " " ) } if err := yaml . Unmarshal ( [ ] byte ( `- apiVersion: v1
  fieldsV1:
    f:field: {}
  manager: foo
  operation: Apply
` ) , & unmarshaled ) ; err != nil { t . Fatalf ( " " , err ) } if _ , err := decodeManagedFields ( unmarshaled ) ; err == nil { t . Fatal ( " " ) } }
TestHasFieldsType makes sure that we fail if we don't have a
FieldsType set properly.
TestHasFieldsType makes sure that we fail if we don ' t have a FieldsType set properly .
// Invalid fieldsType V2. // Missing fieldsType.