-
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: implement Delete endpoint tests
Implements basic Delete endpoint tests, identical to the Get endpoint tests.
- Loading branch information
Showing
28 changed files
with
2,103 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,18 @@ | ||
package deletion | ||
|
||
import ( | ||
"github.com/einride/protoc-gen-go-aip-test/internal/suite" | ||
) | ||
|
||
// Suite of Delete tests. | ||
//nolint: gochecknoglobals | ||
var Suite = suite.Suite{ | ||
Name: "Delete", | ||
Tests: []suite.Test{ | ||
missingName, | ||
invalidName, | ||
exists, | ||
notFound, | ||
wildcardName, | ||
}, | ||
} |
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,39 @@ | ||
package deletion | ||
|
||
import ( | ||
"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 exists = suite.Test{ | ||
Name: "exists", | ||
Doc: []string{ | ||
"Resource should be deleted without errors if it exists.", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeDelete), | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
deleteMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeDelete) | ||
|
||
if util.HasParent(scope.Resource) { | ||
f.P("parent := ", ident.FixtureNextParent, "(t, false)") | ||
f.P("created := fx.create(t, parent)") | ||
} else { | ||
f.P("created := fx.create(t)") | ||
} | ||
util.MethodDelete{ | ||
Resource: scope.Resource, | ||
Method: deleteMethod, | ||
Name: "created.Name", | ||
}.Generate(f, "_", "err", ":=") | ||
f.P(ident.AssertNilError, "(t, err)") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package deletion | ||
|
||
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/grpc/codes" | ||
"google.golang.org/protobuf/compiler/protogen" | ||
) | ||
|
||
//nolint: gochecknoglobals | ||
var invalidName = suite.Test{ | ||
Name: "invalid name", | ||
Doc: []string{ | ||
"Method should fail with InvalidArgument if the provided name is not valid.", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeDelete), | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
deleteMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeDelete) | ||
util.MethodDelete{ | ||
Resource: scope.Resource, | ||
Method: deleteMethod, | ||
Name: strconv.Quote("invalid resource name"), | ||
}.Generate(f, "_", "err", ":=") | ||
f.P(ident.AssertEqual, "(t, ", ident.Codes(codes.InvalidArgument), ",", ident.StatusCode, "(err), err)") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package deletion | ||
|
||
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/grpc/codes" | ||
"google.golang.org/protobuf/compiler/protogen" | ||
) | ||
|
||
//nolint: gochecknoglobals | ||
var missingName = suite.Test{ | ||
Name: "missing name", | ||
Doc: []string{ | ||
"Method should fail with InvalidArgument if no name is provided.", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeDelete), | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
deleteMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeDelete) | ||
util.MethodDelete{ | ||
Resource: scope.Resource, | ||
Method: deleteMethod, | ||
Name: strconv.Quote(""), | ||
}.Generate(f, "_", "err", ":=") | ||
f.P(ident.AssertEqual, "(t, ", ident.Codes(codes.InvalidArgument), ",", ident.StatusCode, "(err), err)") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package deletion | ||
|
||
import ( | ||
"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/grpc/codes" | ||
"google.golang.org/protobuf/compiler/protogen" | ||
) | ||
|
||
//nolint: gochecknoglobals | ||
var notFound = suite.Test{ | ||
Name: "not found", | ||
Doc: []string{ | ||
"Method should fail with NotFound if the resource does not exist.", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeDelete), | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
deleteMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeDelete) | ||
|
||
if util.HasParent(scope.Resource) { | ||
f.P("parent := ", ident.FixtureNextParent, "(t, false)") | ||
f.P("created := fx.create(t, parent)") | ||
} else { | ||
f.P("created := fx.create(t)") | ||
} | ||
util.MethodDelete{ | ||
Resource: scope.Resource, | ||
Method: deleteMethod, | ||
// appending to the resource name ensures it is valid | ||
Name: "created.Name + \"notfound\"", | ||
}.Generate(f, "_", "err", ":=") | ||
f.P(ident.AssertEqual, "(t, ", ident.Codes(codes.NotFound), ",", ident.StatusCode, "(err), err)") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package deletion | ||
|
||
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/grpc/codes" | ||
"google.golang.org/protobuf/compiler/protogen" | ||
) | ||
|
||
//nolint: gochecknoglobals | ||
var wildcardName = suite.Test{ | ||
Name: "only wildcards", | ||
Doc: []string{ | ||
"Method should fail with InvalidArgument if the provided name only contains wildcards ('-')", | ||
}, | ||
|
||
OnlyIf: suite.OnlyIfs( | ||
onlyif.HasMethod(aipreflect.MethodTypeDelete), | ||
), | ||
Generate: func(f *protogen.GeneratedFile, scope suite.Scope) error { | ||
deleteMethod, _ := util.StandardMethod(scope.Service, scope.Resource, aipreflect.MethodTypeDelete) | ||
util.MethodDelete{ | ||
Resource: scope.Resource, | ||
Method: deleteMethod, | ||
Name: strconv.Quote(util.WildcardResourceName(scope.Resource)), | ||
}.Generate(f, "_", "err", ":=") | ||
f.P(ident.AssertEqual, "(t, ", ident.Codes(codes.InvalidArgument), ",", ident.StatusCode, "(err), err)") | ||
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
106 changes: 106 additions & 0 deletions
106
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.
Oops, something went wrong.