MCPcopy Create free account
hub / github.com/dagger/dagger / TestEnumDefaultValue

Method TestEnumDefaultValue

core/integration/module_python_test.go:2214–2258  ·  view source on GitHub ↗

TestEnumDefaultValue verifies that an enum used as a default for a function argument is honored both at call time and in the --help text. Regression test: the --help output used to drop the default for enum-typed args because the engine reconstructed the Query type's typedef from GraphQL introspect

(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

2212// rather than JSON strings (e.g. "RED"). The CLI couldn't parse the bare
2213// identifier as JSON, so it silently fell back to "no default".
2214func (PythonSuite) TestEnumDefaultValue(ctx context.Context, t *testctx.T) {
2215 c := connect(ctx, t)
2216
2217 modGen := pythonModInit(t, c, `
2218import enum
2219import dagger
2220
2221@dagger.enum_type
2222class Color(enum.Enum):
2223 RED = "RED"
2224 BLUE = "BLUE"
2225
2226@dagger.object_type
2227class Test:
2228 @dagger.function
2229 def pick(self, color: Color = Color.RED) -> str:
2230 return color.value
2231`)
2232
2233 t.Run("default value applied at call time", func(ctx context.Context, t *testctx.T) {
2234 out, err := modGen.With(daggerCall("pick")).Stdout(ctx)
2235 require.NoError(t, err)
2236 require.Equal(t, "RED", out)
2237 })
2238
2239 t.Run("explicit value overrides default", func(ctx context.Context, t *testctx.T) {
2240 out, err := modGen.With(daggerCall("pick", "--color", "BLUE")).Stdout(ctx)
2241 require.NoError(t, err)
2242 require.Equal(t, "BLUE", out)
2243 })
2244
2245 t.Run("default shown in --help output", func(ctx context.Context, t *testctx.T) {
2246 out, err := modGen.With(daggerCall("pick", "--help")).Stdout(ctx)
2247 require.NoError(t, err)
2248 require.Contains(t, out, "default RED",
2249 "--help should display the enum default value")
2250 })
2251
2252 t.Run("default registered in module schema", func(ctx context.Context, t *testctx.T) {
2253 schema := inspectModule(ctx, t, modGen)
2254 got := schema.Get(`objects.#.asObject|#(name=Test).functions.#(name=pick).args.#(name=color).defaultValue`).String()
2255 require.Equal(t, `"RED"`, got,
2256 "defaultValue must be a JSON-encoded string, not a bare identifier")
2257 })
2258}

Callers

nothing calls this directly

Calls 11

pythonModInitFunction · 0.85
daggerCallFunction · 0.85
connectFunction · 0.70
inspectModuleFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
ContainsMethod · 0.65
StringMethod · 0.65
GetMethod · 0.65
StdoutMethod · 0.45
WithMethod · 0.45

Tested by

no test coverage detected