-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the Pubsub UserAgent format (close #362)
- Loading branch information
Showing
5 changed files
with
64 additions
and
7 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
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
42 changes: 42 additions & 0 deletions
42
.../scala/com.snowplowanalytics.snowplow.collectors.scalastream/sinks/GcpUserAgentSpec.scala
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,42 @@ | ||
/* | ||
* Copyright (c) 2023 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, and | ||
* you may not use this file except in compliance with the Apache License | ||
* Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Apache License Version 2.0 is distributed on an "AS | ||
* IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the Apache License Version 2.0 for the specific language | ||
* governing permissions and limitations there under. | ||
*/ | ||
package com.snowplowanalytics.snowplow.collectors.scalastream.sinks | ||
|
||
import java.util.regex.Pattern | ||
|
||
import com.snowplowanalytics.snowplow.collectors.scalastream.model._ | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
class GcpUserAgentSpec extends Specification { | ||
|
||
"createUserAgent" should { | ||
"create user agent string correctly" in { | ||
val gcpUserAgent = GcpUserAgent(productName = "Snowplow OSS") | ||
val resultUserAgent = GooglePubSubSink.createUserAgent(gcpUserAgent) | ||
val expectedUserAgent = s"Snowplow OSS/collector (GPN:Snowplow;)" | ||
|
||
val userAgentRegex = Pattern.compile( | ||
"""(?iU)(?:[^\(\)\/]+\/[^\/]+\s+)*(?:[^\s][^\(\)\/]+\/[^\/]+\s?\([^\(\)]*)gpn:(.*)[;\)]""" | ||
) | ||
val matcher = userAgentRegex.matcher(resultUserAgent) | ||
val matched = if (matcher.find()) Some(matcher.group(1)) else None | ||
val expectedMatched = "Snowplow;" | ||
|
||
resultUserAgent must beEqualTo(expectedUserAgent) | ||
matched must beSome(expectedMatched) | ||
} | ||
} | ||
} |