|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +package auto |
| 6 | + |
| 7 | +import ( |
| 8 | + "github.com/siderolabs/gen/maps" |
| 9 | + |
| 10 | + "github.com/siderolabs/kres/internal/project/common" |
| 11 | + "github.com/siderolabs/kres/internal/project/golang" |
| 12 | +) |
| 13 | + |
| 14 | +// DetectIntegrationTests checks if the Go project has any integration tests. |
| 15 | +func (builder *builder) DetectIntegrationTests() (bool, error) { |
| 16 | + var integrationTests IntegrationTests |
| 17 | + |
| 18 | + if err := builder.meta.Config.Load(&integrationTests); err != nil { |
| 19 | + return false, err |
| 20 | + } |
| 21 | + |
| 22 | + return len(integrationTests.Tests) > 0, nil |
| 23 | +} |
| 24 | + |
| 25 | +// BuildIntegrationTests builds Go integration tests. |
| 26 | +func (builder *builder) BuildIntegrationTests() error { |
| 27 | + var integrationTests IntegrationTests |
| 28 | + |
| 29 | + if err := builder.meta.Config.Load(&integrationTests); err != nil { |
| 30 | + return err |
| 31 | + } |
| 32 | + |
| 33 | + for _, spec := range integrationTests.Tests { |
| 34 | + build := golang.NewBuild(builder.meta, spec.Name, spec.Path, "go test -c -covermode=atomic") |
| 35 | + |
| 36 | + build.Outputs = maps.Map(spec.Outputs, func(k string, m map[string]string) (string, golang.CompileConfig) { |
| 37 | + return k, golang.CompileConfig(m) |
| 38 | + }) |
| 39 | + |
| 40 | + build.BuildFlags = append(build.BuildFlags, "-tags integration,sidero.debug") |
| 41 | + |
| 42 | + builder.targets = append(builder.targets, build) |
| 43 | + |
| 44 | + if spec.EnableDockerImage { |
| 45 | + image := common.NewImage( |
| 46 | + builder.meta, spec.Name, |
| 47 | + ) |
| 48 | + |
| 49 | + image.AddInput(build) |
| 50 | + |
| 51 | + builder.targets = append(builder.targets, image) |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + return nil |
| 56 | +} |
0 commit comments