Skip to content

Commit

Permalink
Add presenter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blowmage committed Jun 28, 2019
1 parent 33cc606 commit 2c3f0cc
Show file tree
Hide file tree
Showing 17 changed files with 731 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def initialize api, file
@file = file
end

def name
@file.name
end

def address
@file.address
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def initialize api, package
@package = package
end

def def gem
GemPresenter.new.new @api
def gem
GemPresenter.new @api
end

def name
Expand Down
38 changes: 38 additions & 0 deletions gapic-generator/test/google/gapic/presenters/file/garbage_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class GarbageFilePresenterTest < PresenterTest
def schema
api :garbage
end

def test_garbage
file = schema.files.find { |f| f.name == "garbage/garbage.proto" }
fp = FilePresenter.new schema, file

assert_equal ["endless", "trash", "forever"], fp.address
assert_equal "So::Much::Trash", fp.namespace
assert_equal "garbage/garbage.rb", fp.docs_file_path

assert_equal ["LongRunningGarbageRequest", "LongRunningGarbageResponse", "LongRunningGarbageMetadata", "ListGarbageRequest", "ListGarbageResponse", "GarbageItem", "SimpleGarbage", "SimpleGarbageItem", "TypicalGarbage", "SpecificGarbage", "RepeatedGarbage", "GarbageMap"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal ["GarbageEnum"], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class GoogleAdsFilePresenterTest < PresenterTest
def schema
api :googleads
end

def test_campaign_service
file = schema.files.find { |f| f.name == "google/ads/googleads/v1/services/campaign_service.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "ads", "googleads", "v1", "services"], fp.address
assert_equal "Google::Ads::GoogleAds::V1::Services", fp.namespace
assert_equal "google/ads/googleads/v1/services/campaign_service.rb", fp.docs_file_path

assert_equal ["GetCampaignRequest", "MutateCampaignsRequest", "CampaignOperation", "MutateCampaignsResponse", "MutateCampaignResult"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end
end
83 changes: 83 additions & 0 deletions gapic-generator/test/google/gapic/presenters/file/showcase_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class ShowcaseFilePresenterTest < PresenterTest
def schema
api :showcase
end

def test_echo
file = schema.files.find { |f| f.name == "google/showcase/v1alpha3/echo.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "showcase", "v1alpha3"], fp.address
assert_equal "Google::Showcase::V1alpha3", fp.namespace
assert_equal "google/showcase/v1alpha3/echo.rb", fp.docs_file_path

assert_equal ["EchoRequest", "EchoResponse", "ExpandRequest", "PagedExpandRequest", "PagedExpandResponse", "WaitRequest", "WaitResponse", "WaitMetadata"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_identity
file = schema.files.find { |f| f.name == "google/showcase/v1alpha3/identity.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "showcase", "v1alpha3"], fp.address
assert_equal "Google::Showcase::V1alpha3", fp.namespace
assert_equal "google/showcase/v1alpha3/identity.rb", fp.docs_file_path

assert_equal ["User", "CreateUserRequest", "GetUserRequest", "UpdateUserRequest", "DeleteUserRequest", "ListUsersRequest", "ListUsersResponse"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_messaging
file = schema.files.find { |f| f.name == "google/showcase/v1alpha3/messaging.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "showcase", "v1alpha3"], fp.address
assert_equal "Google::Showcase::V1alpha3", fp.namespace
assert_equal "google/showcase/v1alpha3/messaging.rb", fp.docs_file_path

assert_equal ["Room", "CreateRoomRequest", "GetRoomRequest", "UpdateRoomRequest", "DeleteRoomRequest", "ListRoomsRequest", "ListRoomsResponse", "Blurb", "CreateBlurbRequest", "GetBlurbRequest", "UpdateBlurbRequest", "DeleteBlurbRequest", "ListBlurbsRequest", "ListBlurbsResponse", "SearchBlurbsRequest", "SearchBlurbsMetadata", "SearchBlurbsResponse", "StreamBlurbsRequest", "StreamBlurbsResponse", "SendBlurbsResponse", "ConnectRequest"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_testing
file = schema.files.find { |f| f.name == "google/showcase/v1alpha3/testing.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "showcase", "v1alpha3"], fp.address
assert_equal "Google::Showcase::V1alpha3", fp.namespace
assert_equal "google/showcase/v1alpha3/testing.rb", fp.docs_file_path

assert_equal ["Session", "CreateSessionRequest", "GetSessionRequest", "ListSessionsRequest", "ListSessionsResponse", "DeleteSessionRequest", "ReportSessionRequest", "ReportSessionResponse", "Test", "Issue", "ListTestsRequest", "ListTestsResponse", "TestRun", "DeleteTestRequest", "VerifyTestRequest", "VerifyTestResponse"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end
end
38 changes: 38 additions & 0 deletions gapic-generator/test/google/gapic/presenters/file/speech_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class SpeechFilePresenterTest < PresenterTest
def schema
api :speech
end

def test_cloud_speech
file = schema.files.find { |f| f.name == "google/cloud/speech/v1/cloud_speech.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "speech", "v1"], fp.address
assert_equal "Google::Cloud::Speech::V1", fp.namespace
assert_equal "google/cloud/speech/v1/cloud_speech.rb", fp.docs_file_path

assert_equal ["RecognizeRequest", "LongRunningRecognizeRequest", "StreamingRecognizeRequest", "StreamingRecognitionConfig", "RecognitionConfig", "SpeechContext", "RecognitionAudio", "RecognizeResponse", "LongRunningRecognizeResponse", "LongRunningRecognizeMetadata", "StreamingRecognizeResponse", "StreamingRecognitionResult", "SpeechRecognitionResult", "SpeechRecognitionAlternative", "WordInfo"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end
end
113 changes: 113 additions & 0 deletions gapic-generator/test/google/gapic/presenters/file/vision_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class VisionFilePresenterTest < PresenterTest
def schema
api :vision
end

def test_geometry
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/geometry.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/geometry.rb", fp.docs_file_path

assert_equal ["Vertex", "NormalizedVertex", "BoundingPoly", "Position"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_product_search_service
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/product_search_service.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/product_search_service.rb", fp.docs_file_path

assert_equal ["Product", "ProductSet", "ReferenceImage", "CreateProductRequest", "ListProductsRequest", "ListProductsResponse", "GetProductRequest", "UpdateProductRequest", "DeleteProductRequest", "CreateProductSetRequest", "ListProductSetsRequest", "ListProductSetsResponse", "GetProductSetRequest", "UpdateProductSetRequest", "DeleteProductSetRequest", "CreateReferenceImageRequest", "ListReferenceImagesRequest", "ListReferenceImagesResponse", "GetReferenceImageRequest", "DeleteReferenceImageRequest", "AddProductToProductSetRequest", "RemoveProductFromProductSetRequest", "ListProductsInProductSetRequest", "ListProductsInProductSetResponse", "ImportProductSetsGcsSource", "ImportProductSetsInputConfig", "ImportProductSetsRequest", "ImportProductSetsResponse", "BatchOperationMetadata"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_product_search
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/product_search.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/product_search.rb", fp.docs_file_path

assert_equal ["ProductSearchParams", "ProductSearchResults"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_text_annotation
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/text_annotation.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/text_annotation.rb", fp.docs_file_path

assert_equal ["TextAnnotation", "Page", "Block", "Paragraph", "Word", "Symbol"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_web_detection
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/web_detection.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/web_detection.rb", fp.docs_file_path

assert_equal ["WebDetection"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal [], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end

def test_image_annotator
file = schema.files.find { |f| f.name == "google/cloud/vision/v1/image_annotator.proto" }
fp = FilePresenter.new schema, file

assert_equal ["google", "cloud", "vision", "v1"], fp.address
assert_equal "Google::Cloud::Vision::V1", fp.namespace
assert_equal "google/cloud/vision/v1/image_annotator.rb", fp.docs_file_path

assert_equal ["Feature", "ImageSource", "Image", "FaceAnnotation", "LocationInfo", "Property", "EntityAnnotation", "LocalizedObjectAnnotation", "SafeSearchAnnotation", "LatLongRect", "ColorInfo", "DominantColorsAnnotation", "ImageProperties", "CropHint", "CropHintsAnnotation", "CropHintsParams", "WebDetectionParams", "ImageContext", "AnnotateImageRequest", "ImageAnnotationContext", "AnnotateImageResponse", "AnnotateFileResponse", "BatchAnnotateImagesRequest", "BatchAnnotateImagesResponse", "AsyncAnnotateFileRequest", "AsyncAnnotateFileResponse", "AsyncBatchAnnotateFilesRequest", "AsyncBatchAnnotateFilesResponse", "InputConfig", "OutputConfig", "GcsSource", "GcsDestination", "OperationMetadata"], fp.messages.map(&:name)
fp.messages.each { |mp| assert_kind_of MessagePresenter, mp }

assert_equal ["Likelihood"], fp.enums.map(&:name)
fp.enums.each { |ep| assert_kind_of EnumPresenter, ep }
end
end
49 changes: 49 additions & 0 deletions gapic-generator/test/google/gapic/presenters/gem/garbage_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "test_helper"

class GarbageGemPresenterTest < PresenterTest
def presenter
GemPresenter.new api :garbage
end

def test_garbage
assert_equal ["Google", "Garbage"], presenter.address
assert_equal "google-garbage", presenter.name
assert_equal "Google::Garbage", presenter.namespace
assert_equal "Google Garbage", presenter.title
assert_equal "0.0.1", presenter.version
assert_equal "google/garbage/version", presenter.version_require
assert_equal "google/garbage/version.rb", presenter.version_file_path
assert_equal "Google::Garbage::VERSION", presenter.version_name_full
assert_equal ["Google LLC"], presenter.authors
assert_equal "[email protected]", presenter.email
assert_equal "google-garbage is the official library for Google Garbage API.", presenter.description
assert_equal "API Client library for Google Garbage API", presenter.summary
assert_equal "https://github.com/googleapis/googleapis", presenter.homepage
assert_equal "GARBAGE", presenter.env_prefix

assert_equal ["endless.trash.forever"], presenter.packages.map(&:name)
presenter.packages.each { |pp| assert_kind_of PackagePresenter, pp }

assert_equal ["GarbageService"], presenter.services.map(&:name)
presenter.services.each { |sp| assert_kind_of ServicePresenter, sp }

assert_equal ["google/api/http.proto", "google/protobuf/descriptor.proto", "google/api/client.proto", "google/api/field_behavior.proto", "google/api/resource.proto", "google/protobuf/any.proto", "google/protobuf/empty.proto", "google/rpc/status.proto", "google/longrunning/operations.proto", "google/protobuf/timestamp.proto", "garbage/garbage.proto"], presenter.proto_files.map(&:name)
presenter.proto_files.each { |fp| assert_kind_of FilePresenter, fp }
end
end
Loading

0 comments on commit 2c3f0cc

Please sign in to comment.