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

Method TestCustomSDK

core/integration/module_test.go:2158–2324  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

2156}
2157
2158func (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
2168import (
2169 "context"
2170 "encoding/json"
2171
2172 "dagger/cool-sdk/internal/dagger"
2173)
2174
2175type CoolSdk struct {}
2176
2177func (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
2195func (m *CoolSdk) ModuleRuntime(modSource *dagger.ModuleSource, introspectionJson *dagger.File) *dagger.Container {
2196 return modSource.WithSDK("go").AsModule().Runtime().WithEnvVariable("COOL", "true")
2197}
2198
2199func (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
2208import "os"
2209
2210type Test struct {}
2211
2212func (m *Test) Fn() string {
2213 return os.Getenv("COOL")
2214}
2215`,

Callers

nothing calls this directly

Calls 15

daggerCliFileFunction · 0.85
daggerExecFunction · 0.85
daggerCallFunction · 0.85
testOnMultipleVCSFunction · 0.85
privateRepoSetupFunction · 0.85
goGitBaseFunction · 0.85
testGitModuleRefFunction · 0.85
daggerFunctionsFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected