MCPcopy
hub / github.com/purpleidea/mgmt / TestAstFunc3

Function TestAstFunc3

lang/interpret_test.go:1562–2588  ·  view source on GitHub ↗

TestAstFunc3 is an even more advanced version which also examines parameter values. It briefly runs the function engine and captures output. Only use with stable, static output. It also briefly runs the resource engine too!

(t *testing.T)

Source from the content-addressed store, hash-verified

1560// values. It briefly runs the function engine and captures output. Only use
1561// with stable, static output. It also briefly runs the resource engine too!
1562func TestAstFunc3(t *testing.T) {
1563 const magicError = "# err: "
1564 const magicErrorLexParse = "errLexParse: "
1565 const magicErrorInit = "errInit: "
1566 const magicInterpolate = "errInterpolate: "
1567 const magicErrorSetScope = "errSetScope: "
1568 const magicErrorUnify = "errUnify: "
1569 const magicErrorGraph = "errGraph: "
1570 const magicErrorInterpret = "errInterpret: "
1571 const magicErrorAutoEdge = "errAutoEdge: "
1572 const magicErrorValidate = "errValidate: "
1573 const magicEmpty = "# empty!"
1574 dir, err := util.TestDirFull()
1575 if err != nil {
1576 t.Errorf("could not get tests directory: %+v", err)
1577 return
1578 }
1579 t.Logf("tests directory is: %s", dir)
1580
1581 type test struct { // an individual test
1582 name string
1583 path string // relative txtar path inside tests dir
1584 }
1585 testCases := []test{}
1586
1587 // build test array automatically from reading the dir
1588 files, err := os.ReadDir(dir)
1589 if err != nil {
1590 t.Errorf("could not read through tests directory: %+v", err)
1591 return
1592 }
1593 sorted := []string{}
1594 for _, f := range files {
1595 if f.IsDir() {
1596 continue
1597 }
1598 if !strings.HasSuffix(f.Name(), ".txtar") {
1599 continue
1600 }
1601
1602 sorted = append(sorted, f.Name())
1603 }
1604 sort.Strings(sorted)
1605 for _, f := range sorted {
1606 // add automatic test case
1607 testCases = append(testCases, test{
1608 name: f,
1609 path: f, // <something>.txtar
1610 })
1611 }
1612
1613 if testing.Short() {
1614 t.Logf("available tests:")
1615 }
1616 names := []string{}
1617 for index, tc := range testCases { // run all the tests
1618 if tc.name == "" {
1619 t.Errorf("test #%d: not named", index)

Callers

nothing calls this directly

Calls 15

ConnectMethod · 0.95
CleanupMethod · 0.95
AddVertexMethod · 0.95
ExecGraphvizMethod · 0.95
UnifyMethod · 0.95
SetupMethod · 0.95
TxnMethod · 0.95
RunMethod · 0.95
ErrMethod · 0.95
StreamMethod · 0.95
InterpretMethod · 0.95
InitMethod · 0.95

Tested by

no test coverage detected