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)
| 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". |
| 2214 | func (PythonSuite) TestEnumDefaultValue(ctx context.Context, t *testctx.T) { |
| 2215 | c := connect(ctx, t) |
| 2216 | |
| 2217 | modGen := pythonModInit(t, c, ` |
| 2218 | import enum |
| 2219 | import dagger |
| 2220 | |
| 2221 | @dagger.enum_type |
| 2222 | class Color(enum.Enum): |
| 2223 | RED = "RED" |
| 2224 | BLUE = "BLUE" |
| 2225 | |
| 2226 | @dagger.object_type |
| 2227 | class 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 | } |
nothing calls this directly
no test coverage detected