Ejemplo n.º 1
0
// Finish completes and returns the object. If errors were encountered during
// loading, they're all returned here as type Errors.
func (loader *Loader) Finish() (interface{}, error) {
	if loader.links != nil {
		for src, target := range loader.links {
			var value interface{}

			dst, err := loader.resolve(target, 0)

			klog.KPrintf("blueprint.loader.finish.debug", "src=%s, target=%s", src, dst)

			if err == nil {
				if value, err = dst.Get(loader.Values); err == nil && value == nil {
					err = fmt.Errorf("unable to link '%s' to nil value '%s'", src, dst)
				}
			}

			if err == nil {
				err = path.New(src).Set(loader.Values, value)
			}

			if err != nil {
				loader.ErrorAt(err, path.New(src))
			}
		}
	}

	// Required otherwise we set the type param on the error interface which
	// makes the error non-nil. One of those fun parts of the go language.
	if loader.errors != nil {
		return nil, loader.errors
	}
	return loader.Values, nil
}
Ejemplo n.º 2
0
func (loader *Loader) TestLink(t *testing.T, src, target string) {
	n := len(loader.errors)

	loader.Link(path.New(src), path.New(target))

	if i := len(loader.errors); n != i {
		t.Errorf("FAIL: error during type(%s, %s)  -> %s", src, target, Errors(loader.errors[n:]))
	}
}
Ejemplo n.º 3
0
func (loader *Loader) TestType(t *testing.T, src, name string) {
	n := len(loader.errors)

	loader.Type(path.New(src), name)

	if i := len(loader.errors); n != i {
		t.Errorf("FAIL: error during type(%s, %s) -> %s", src, name, Errors(loader.errors[n:]))
	}
}
Ejemplo n.º 4
0
func (loader *Loader) TestAdd(t *testing.T, src string, value interface{}) {
	n := len(loader.errors)

	loader.Add(path.New(src), value)

	if i := len(loader.errors); n != i {
		t.Errorf("FAIL: error during add(%s, %v) -> %s", src, value, Errors(loader.errors[n:]))
	}
}
Ejemplo n.º 5
0
func (loader *loaderJSON) loadLinks(current path.P, obj interface{}) {
	switch obj.(type) {

	case string:
		loader.Link(current, path.New(obj.(string)))

	case []interface{}:
		for i, value := range obj.([]interface{}) {
			loader.loadLinks(append(current, strconv.Itoa(i)), value)
		}

	default:
		loader.ErrorAt(fmt.Errorf("unknown object type '%T' for links", obj), current)
	}
}