internal/gapicgen: report test failures directly
This keeps the test failure and cause in the same location. t.Errorf
will continue executing the test (t.Fatalf stops execution). See
https://github.com/golang/go/wiki/TestComments#keep-going.
Also, I put the import path first since it's the more useful part for
finding the failing config. But, the import path may be empty, so I left
the index in
(https://github.com/golang/go/wiki/TestComments#identify-the-input is
relevant).
This results in failures like:
--- FAIL: TestMicrogenConfigs (0.00s)
/.../internal/gapicgen/generator/config_test.go:43: config "cloud.google.com/go/texttospeech/apiv1" (#0) expected non-empty pkg field
/.../internal/gapicgen/generator/config_test.go:59: config "cloud.google.com/go/language/apiv1" (#2) invalid release level: "alphaa"
Change-Id: If92888c1fd21484ea92918ebbdb362b8400a6bac
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/50810
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Noah Dietz <ndietz@google.com>
diff --git a/internal/gapicgen/generator/config_test.go b/internal/gapicgen/generator/config_test.go
index 57fd2cb..7a0a4b9 100644
--- a/internal/gapicgen/generator/config_test.go
+++ b/internal/gapicgen/generator/config_test.go
@@ -15,8 +15,6 @@
package generator
import (
- "bytes"
- "fmt"
"testing"
)
@@ -35,42 +33,30 @@
// to ensure referenced entries are present.
func TestMicrogenConfigs(t *testing.T) {
for k, entry := range microgenGapicConfigs {
- // Collect all the problems for a given entry and report them once.
- var errors []error
-
if entry.importPath == "" {
- errors = append(errors, fmt.Errorf("expected non-empty import field"))
+ t.Errorf("config %q (#%d) expected non-empty importPath", entry.inputDirectoryPath, k)
}
if entry.inputDirectoryPath == "" {
- errors = append(errors, fmt.Errorf("expected non-empty inputDirectoryPath field"))
+ t.Errorf("config %q (#%d) expected non-empty inputDirectoryPath field", entry.importPath, k)
}
if entry.pkg == "" {
- errors = append(errors, fmt.Errorf("expected non-empty pkg field"))
+ t.Errorf("config %q (#%d) expected non-empty pkg field", entry.importPath, k)
}
// TODO: Consider if we want to allow this at a later point in time. If this
// isn't supplied the config is technically valid, but the generated library
// won't include features such as retry policies.
if entry.gRPCServiceConfigPath == "" {
- errors = append(errors, fmt.Errorf("expected non-empty gRPCServiceConfigPath"))
+ t.Errorf("config %q (#%d) expected non-empty gRPCServiceConfigPath", entry.importPath, k)
}
if entry.apiServiceConfigPath == "" {
- errors = append(errors, fmt.Errorf("expected non-empty apiServiceConfigPath"))
+ t.Errorf("config %q (#%d) expected non-empty apiServiceConfigPath", entry.importPath, k)
}
// Internally, an empty release level means "ga" to the underlying tool, but we
// want to be explicit in this configuration.
if entry.releaseLevel == "" {
- errors = append(errors, fmt.Errorf("expected non-empty releaseLevel field"))
- } else if _, ok := allowedReleaseLevels[entry.releaseLevel]; !ok {
- errors = append(errors, fmt.Errorf("invalid release level: %s", entry.releaseLevel))
- }
-
- if len(errors) > 0 {
- var b bytes.Buffer
- fmt.Fprintf(&b, "errors with entry #%d (importPath: %s)\n", k, entry.importPath)
- for _, v := range errors {
- fmt.Fprintf(&b, "\t%v\n", v)
- }
- t.Errorf(b.String())
+ t.Errorf("config %q (#%d) expected non-empty releaseLevel field", entry.importPath, k)
+ } else if !allowedReleaseLevels[entry.releaseLevel] {
+ t.Errorf("config %q (#%d) invalid releaseLevel: %q", entry.importPath, k, entry.releaseLevel)
}
}
}