( ctx context.Context, // The test container to run the tests in container *dagger.Container, // Various test options // FIXME merge this into chainable functions instead opts *testOpts, )
| 148 | } |
| 149 | |
| 150 | func (dev *EngineDev) test( |
| 151 | ctx context.Context, |
| 152 | // The test container to run the tests in |
| 153 | container *dagger.Container, |
| 154 | // Various test options |
| 155 | // FIXME merge this into chainable functions instead |
| 156 | opts *testOpts, |
| 157 | ) *dagger.Container { |
| 158 | if opts.envs != nil { |
| 159 | container = container.WithMountedSecret("/dagger.env", opts.envs) |
| 160 | } |
| 161 | |
| 162 | cgoEnabledEnv := "0" |
| 163 | args := []string{ |
| 164 | "otelgotest", |
| 165 | } |
| 166 | |
| 167 | // allow verbose |
| 168 | if opts.testVerbose { |
| 169 | args = append(args, "-v") |
| 170 | } |
| 171 | |
| 172 | // Add ldflags |
| 173 | version, err := dag.Version().Version(ctx) |
| 174 | if err != nil { |
| 175 | return dag.Container().WithError(err.Error()) |
| 176 | } |
| 177 | tag, err := dag.Version().ImageTag(ctx) |
| 178 | if err != nil { |
| 179 | return dag.Container().WithError(err.Error()) |
| 180 | } |
| 181 | ldflags := []string{ |
| 182 | "-X", "github.com/dagger/dagger/engine.Version=" + version, |
| 183 | "-X", "github.com/dagger/dagger/engine.Tag=" + tag, |
| 184 | } |
| 185 | args = append(args, "-ldflags", strings.Join(ldflags, " ")) |
| 186 | |
| 187 | // All following are go test flags |
| 188 | if opts.failfast { |
| 189 | args = append(args, "-failfast") |
| 190 | } |
| 191 | |
| 192 | // Go will default parallel to number of CPUs, so only pass if set |
| 193 | if opts.parallel != 0 { |
| 194 | args = append(args, fmt.Sprintf("-parallel=%d", opts.parallel)) |
| 195 | } |
| 196 | |
| 197 | // Default timeout to 30m |
| 198 | // No test suite should take more than 30 minutes to run |
| 199 | if opts.timeout == "" { |
| 200 | opts.timeout = "30m" |
| 201 | } |
| 202 | args = append(args, fmt.Sprintf("-timeout=%s", opts.timeout)) |
| 203 | |
| 204 | if opts.race { |
| 205 | args = append(args, "-race") |
| 206 | cgoEnabledEnv = "1" |
| 207 | } |
no test coverage detected