github.com/GuanceCloud/cliutils@v1.1.21/pipeline/ptinput/funcs/all_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  package funcs
     7  
     8  import (
     9  	"fmt"
    10  
    11  	"github.com/GuanceCloud/cliutils/pipeline/ptinput"
    12  	"github.com/GuanceCloud/platypus/pkg/engine"
    13  	"github.com/GuanceCloud/platypus/pkg/engine/runtime"
    14  	"github.com/GuanceCloud/platypus/pkg/errchain"
    15  )
    16  
    17  func NewTestingRunner(script string) (*runtime.Script, error) {
    18  	name := "default.p"
    19  	ret1, ret2 := engine.ParseScript(map[string]string{
    20  		"default.p": script,
    21  	},
    22  		FuncsMap, FuncsCheckMap,
    23  	)
    24  	if len(ret1) > 0 {
    25  		return ret1[name], nil
    26  	}
    27  	if len(ret2) > 0 {
    28  		return nil, ret2[name]
    29  	}
    30  	return nil, fmt.Errorf("parser func error")
    31  }
    32  
    33  func NewTestingRunner2(scripts map[string]string) (map[string]*runtime.Script, map[string]error) {
    34  	return engine.ParseScript(scripts, FuncsMap, FuncsCheckMap)
    35  }
    36  
    37  func runScript(proc *runtime.Script, pt ptinput.PlInputPt, fn ...runtime.TaskFn) *errchain.PlError {
    38  	return proc.Run(pt, nil, fn...)
    39  }