Skip to content

Commit

Permalink
fix(update): dont mutate the shared resource
Browse files Browse the repository at this point in the history
Causes issues with services with ETags.
  • Loading branch information
ericwenn committed Aug 22, 2021
1 parent d6bc890 commit 11f1056
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 37 deletions.
15 changes: 14 additions & 1 deletion internal/aiptest/update/persisted.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@ var persisted = suite.Test{

OnlyIf: func(scope suite.Scope) bool {
updateMethod, hasUpdate := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate)
createMethod, hasCreate := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeCreate)
_, hasGet := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeGet)
return hasUpdate && !util.ReturnsLRO(updateMethod.Desc) && hasGet
return hasUpdate && !util.ReturnsLRO(updateMethod.Desc) &&
hasCreate && !util.ReturnsLRO(createMethod.Desc) &&
hasGet
},
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error {
updateMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate)
getMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeGet)
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)")
util.MethodUpdate{
Resource: scope.Resource,
Method: updateMethod,
Expand Down
4 changes: 2 additions & 2 deletions internal/aiptest/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var Suite = suite.Suite{
Tests: []suite.Test{
missingName,
invalidName,
updateTime,
persisted,
},
TestGroups: []suite.TestGroup{
withResourceGroup,
Expand All @@ -38,9 +40,7 @@ var withResourceGroup = suite.TestGroup{
return nil
},
Tests: []suite.Test{
updateTime,
notFound,
persisted,
invalidUpdateMask,
requiredFields,
// TODO: add test for supplying wildcard as name
Expand Down
16 changes: 14 additions & 2 deletions internal/aiptest/update/update_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ var updateTime = suite.Test{
},

OnlyIf: func(scope suite.Scope) bool {
updateMethod, ok := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate)
return ok && !util.ReturnsLRO(updateMethod.Desc)
updateMethod, hasUpdate := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate)
createMethod, hasCreate := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeCreate)
return hasUpdate && !util.ReturnsLRO(updateMethod.Desc) &&
hasCreate && !util.ReturnsLRO(createMethod.Desc)
},
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)")
updateMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeUpdate)
util.MethodUpdate{
Resource: scope.Resource,
Expand Down
84 changes: 52 additions & 32 deletions 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.

0 comments on commit 11f1056

Please sign in to comment.