#SDK native test framework support

1 messages ยท Page 1 of 1 (latest)

alpine lantern
#

It's been on the radar to improve support for language native test frameworks like go test. However, I can't find an issue tracking that. It would be a great enhancement/enabler nonetheless.

winter ocean
#

Note that our tests are not for dagger modules, but for the dagger engine itself.

knotty mica
winter ocean
#

And yes, agreed it would be great to have better integration with native go tests

winter ocean
knotty mica
#

For now just having tests is an improvement over yml pipelines, but we have Junit -> reports for other code repos

alpine lantern
knotty mica
winter ocean
#

@neon seal we were just talking about this ๐Ÿ™‚

neon seal
#

On another side, I implemented my one go test runner so I can directly call it from a dagger function without creating a container (it's super hacky but it works)

knotty mica
#

You're not wrong about it being super hacky! I do wonder if there's a different approach: rather than trying to fit Dagger into each language's testing package(s), allow the Dagger module's struct type to be defined as a test module, and expand that into generating junit

#

E.g. a module called tests has type Tests struct{} currently. If that was instead:

type Tests struct{
  Test: true,
}

The module returns a junit XML containing the result of each function in the test module? Something like that, making this up off the top of my head

neon seal
#

Hey there @knotty mica @alpine lantern

I found a way using generated clients to create native test for dagger Go modules, here's an example: https://github.com/TomChv/dagger-native-test-example/tree/main/go

I added an example with a guide in the go directory, it makes testing so easily, you can simply run go test to test your module and the setup is super minimal.

I plan to do tests to also show example on TypeScript using jest or mocha.

It's not possible in other languages for now because it requires standalone client generation (but now we have one more reason to implement that asap ๐Ÿš€)

#

/cc @kind saffron @flat haven @low oar ^^^ it's a pretty cool discovery so I'm pinging you ๐Ÿ˜‰

#

Solomon mentionned that we could generate that as part of dagger init so users have by default tests setup with testctx etc ๐Ÿ˜›

winter ocean
low oar
knotty mica
#

I'll take a look at this today, thanks!

neon seal
knotty mica
neon seal
#

You can run dagger develop to regenerate the client, or you can commit it if you want

#

When you do dagger client install, it will update the dagger.json to store the client path & generator so you can regenerate everything from a single dagger develop ๐Ÿ˜‰

knotty mica
#

Bit bumpy on the generated client @neon seal.

Code in test submodule:

account := dag.
        Aws(dagger.AwsOpts{AccessKey: ak, SecretKey: sk, SessionToken: st}).
        AccountInfo()

Code in main_test.go:

res := dag.
        Aws(
            dagger.AwsOpts{
                AccessKey:    accessKey,
                SecretKey:    secretKey,
                SessionToken: sessionToken,
            },
        ).
        AccountInfo()

Result:

# dagger/dagger-aws/integration/client/dag
integration/client/dag/dag.gen.go:59:20: undefined: region
integration/client/dag/dag.gen.go:59:28: too many arguments in call to client.Aws
    have (unknown type, []"dagger/dagger-aws/integration/client".AwsOpts...)
    want (..."dagger/dagger-aws/integration/client".AwsOpts)
FAIL    dagger/dagger-aws/integration [build failed]
FAIL

Region is an optional argument to Aws that defaults to eu-central-1. When using this module in another module as a dependency the function signature is:

func (r *dagger.Client) Aws(accessKey *dagger.Secret, secretKey *dagger.Secret, sessionToken *dagger.Secret, opts ...dagger.AwsOpts) *dagger.Aws
#

My editor doesn't find the integration package (because there isn't one) and doesn't have autocomplete on dag.Aws or dagger.AwsOpts which makes it trickier

#

The generated client does appear to be missing region:

func Aws(opts ...dagger.AwsOpts) *dagger.Aws {
    client := initClient()
    return client.Aws(region, opts...)
}
neon seal
#

Normally there should be an integration package, that you create to hold your client and your test files

knotty mica
#

Not open source no, i can either try and produce a minimal repro or a quick call next week

neon seal
#

Generated clients are still experimental so I'm happy to fix any bug that we may find ๐Ÿ˜„