MCPcopy Create free account
hub / github.com/goadesign/goa / ResetDSL

Function ResetDSL

expr/testing.go:89–101  ·  view source on GitHub ↗

ResetDSL resets the global expression state for testing and initializes a default API. This function should be called before running any DSL that modifies the global Root or GeneratedResultTypes variables. Usage in tests: func TestMyDSL(t *testing.T) { // Option 1: Use expr.RunDSL which call

(t *testing.T)

Source from the content-addressed store, hash-verified

87// Note: RunDSL and RunInvalidDSL automatically call ResetDSL, so you
88// only need to call it manually when executing DSL code directly.
89func ResetDSL(t *testing.T) {
90 t.Helper()
91 // reset all roots and codegen data structures
92 eval.Reset()
93 Root = new(RootExpr)
94 GeneratedResultTypes = new(ResultTypesRoot)
95 require.NoError(t, eval.Register(Root))
96 require.NoError(t, eval.Register(GeneratedResultTypes))
97
98 // Initialize default API for DSL execution
99 Root.API = NewAPIExpr("test api", func() {})
100 Root.API.Servers = []*ServerExpr{Root.API.DefaultServer()}
101}

Callers 2

RunDSLFunction · 0.85
RunInvalidDSLFunction · 0.85

Calls 4

ResetFunction · 0.92
RegisterFunction · 0.92
NewAPIExprFunction · 0.85
DefaultServerMethod · 0.80

Tested by

no test coverage detected