github.com/awesome-flow/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/corev1alpha1/test/context.go (about)

     1  package test
     2  
     3  import (
     4  	"github.com/awesome-flow/flow/pkg/cfg"
     5  	core "github.com/awesome-flow/flow/pkg/corev1alpha1"
     6  	"github.com/awesome-flow/flow/pkg/types"
     7  )
     8  
     9  func NewContextWithConfig(config map[string]interface{}) (*core.Context, error) {
    10  	repo := cfg.NewRepository()
    11  	for k, v := range config {
    12  		if _, err := cfg.NewScalarConfigProvider(
    13  			&types.KeyValue{
    14  				Key:   types.NewKey(k),
    15  				Value: v,
    16  			},
    17  			repo,
    18  			42, // doesn't matter
    19  		); err != nil {
    20  			return nil, err
    21  		}
    22  	}
    23  
    24  	ctx, err := core.NewContext(core.NewConfig(repo))
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	return ctx, nil
    30  }