-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(update): add test for preserving create_time when "*" update mask
- Loading branch information
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package update | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/einride/protoc-gen-go-aip-test/internal/ident" | ||
"github.com/einride/protoc-gen-go-aip-test/internal/onlyif" | ||
"github.com/einride/protoc-gen-go-aip-test/internal/suite" | ||
"github.com/einride/protoc-gen-go-aip-test/internal/util" | ||
"go.einride.tech/aip/reflect/aipreflect" | ||
"google.golang.org/protobuf/compiler/protogen" | ||
) | ||
|
||
// nolint: gochecknoglobals | ||
var preserveCreateTime = suite.Test{ | ||
Name: "preserve create_time", | ||
Doc: []string{ | ||
"The field create_time should be preserved when a '*'-update mask is used.", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeCreate), | ||
onlyif.MethodNotLRO(aipreflect.MethodTypeCreate), | ||
onlyif.HasMethod(aipreflect.MethodTypeUpdate), | ||
onlyif.MethodNotLRO(aipreflect.MethodTypeUpdate), | ||
onlyif.HasField("create_time"), | ||
onlyif.HasRequiredFields, | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
createMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeCreate) | ||
if util.HasParent(scope.Resource) { | ||
f.P("parent := ", ident.FixtureNextParent, "(t, false)") | ||
} | ||
util.MethodCreate{ | ||
Resource: scope.Resource, | ||
Method: createMethod, | ||
Parent: "parent", | ||
}.Generate(f, "created", "err", ":=") | ||
f.P(ident.AssertNilError, "(t, err)") | ||
f.P("originalCreateTime := created.CreateTime") | ||
updateMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate) | ||
util.MethodUpdate{ | ||
Resource: scope.Resource, | ||
Method: updateMethod, | ||
Msg: "created", | ||
UpdateMask: []string{strconv.Quote("*")}, | ||
}.Generate(f, "updated", "err", ":=") | ||
f.P(ident.AssertNilError, "(t, err)") | ||
f.P(ident.AssertDeepEqual, "(t, originalCreateTime, updated.CreateTime,", ident.ProtocmpTransform, "())") | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
proto/gen/googleapis/cloud/aiplatform/v1/tensorboard_service_aiptest.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.