(ctx context.Context, t *testctx.T)
| 2156 | } |
| 2157 | |
| 2158 | func (ModuleSuite) TestCustomSDK(ctx context.Context, t *testctx.T) { |
| 2159 | t.Run("local", func(ctx context.Context, t *testctx.T) { |
| 2160 | c := connect(ctx, t) |
| 2161 | |
| 2162 | ctr := c.Container().From(golangImage). |
| 2163 | WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). |
| 2164 | WithWorkdir("/work/coolsdk"). |
| 2165 | With(daggerExec("init", "--source=.", "--name=cool-sdk", "--sdk=go")). |
| 2166 | WithNewFile("main.go", `package main |
| 2167 | |
| 2168 | import ( |
| 2169 | "context" |
| 2170 | "encoding/json" |
| 2171 | |
| 2172 | "dagger/cool-sdk/internal/dagger" |
| 2173 | ) |
| 2174 | |
| 2175 | type CoolSdk struct {} |
| 2176 | |
| 2177 | func (m *CoolSdk) ModuleTypes(ctx context.Context, modSource *dagger.ModuleSource, introspectionJSON *dagger.File, outputFilePath string) (*dagger.Container, error) { |
| 2178 | mod := modSource.WithSDK("go").AsModule() |
| 2179 | modID, err := mod.ID(ctx) |
| 2180 | if err != nil { |
| 2181 | return nil, err |
| 2182 | } |
| 2183 | b, err := json.Marshal(modID) |
| 2184 | if err != nil { |
| 2185 | return nil, err |
| 2186 | } |
| 2187 | return dag.Container(). |
| 2188 | From("alpine"). |
| 2189 | WithNewFile(outputFilePath, string(b)). |
| 2190 | WithEntrypoint([]string{ |
| 2191 | "sh", "-c", "", |
| 2192 | }), nil |
| 2193 | } |
| 2194 | |
| 2195 | func (m *CoolSdk) ModuleRuntime(modSource *dagger.ModuleSource, introspectionJson *dagger.File) *dagger.Container { |
| 2196 | return modSource.WithSDK("go").AsModule().Runtime().WithEnvVariable("COOL", "true") |
| 2197 | } |
| 2198 | |
| 2199 | func (m *CoolSdk) Codegen(modSource *dagger.ModuleSource, introspectionJson *dagger.File) *dagger.GeneratedCode { |
| 2200 | return dag.GeneratedCode(modSource.WithSDK("go").AsModule().GeneratedContextDirectory()) |
| 2201 | } |
| 2202 | `, |
| 2203 | ). |
| 2204 | WithWorkdir("/work"). |
| 2205 | With(daggerExec("init", "--source=.", "--name=test", "--sdk=coolsdk")). |
| 2206 | WithNewFile("main.go", `package main |
| 2207 | |
| 2208 | import "os" |
| 2209 | |
| 2210 | type Test struct {} |
| 2211 | |
| 2212 | func (m *Test) Fn() string { |
| 2213 | return os.Getenv("COOL") |
| 2214 | } |
| 2215 | `, |
nothing calls this directly
no test coverage detected