Пример #1
0
// ExtractGet decorates a GetResult struct returned from a networks.Get()
// function with extended attributes.
func ExtractGet(r networks.GetResult) (*NetworkExternal, error) {
	var s struct {
		Network *NetworkExternal `json:"network"`
	}
	err := r.ExtractInto(&s)
	return s.Network, err
}
Пример #2
0
func TestExtractFnsReturnsErrWhenResultContainsErr(t *testing.T) {
	gr := networks.GetResult{}
	gr.Err = errors.New("")

	if _, err := external.ExtractGet(gr); err == nil {
		t.Fatalf("Expected error, got one")
	}

	ur := networks.UpdateResult{}
	ur.Err = errors.New("")

	if _, err := external.ExtractUpdate(ur); err == nil {
		t.Fatalf("Expected error, got one")
	}

	cr := networks.CreateResult{}
	cr.Err = errors.New("")

	if _, err := external.ExtractCreate(cr); err == nil {
		t.Fatalf("Expected error, got one")
	}
}