Skip to content

Commit

Permalink
Merge pull request #16 from ba-st/january_improvements
Browse files Browse the repository at this point in the history
Improve portability
  • Loading branch information
gcotelli authored Jan 14, 2021
2 parents 6538fdd + 36d9a04 commit 80fb3e0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ Class {
#name : #ConsulServiceDiscoveryPluginAPITest,
#superclass : #OperationalPluginAPITest,
#instVars : [
'consulAgent'
'consulAgent',
'consulAgentPort'
],
#category : #'Stargate-Consul-Tests'
}

{ #category : #private }
ConsulServiceDiscoveryPluginAPITest >> consulAgentLocation [

^ 'http://localhost:9998' asUrl
^ 'http://localhost' asUrl port: consulAgentPort
]

{ #category : #logging }
ConsulServiceDiscoveryPluginAPITest >> isLogging [

^ true
]

{ #category : #private }
Expand All @@ -32,6 +39,19 @@ ConsulServiceDiscoveryPluginAPITest >> requiredPermissions [
^ #()
]

{ #category : #private }
ConsulServiceDiscoveryPluginAPITest >> runCase [

| logs |

logs :=
String streamContents: [:stream |
CurrentLogger
value: (LeveledLogger outputTo: stream errorsTo: stream)
during: [super runCase]].
self logFailure: logs
]

{ #category : #private }
ConsulServiceDiscoveryPluginAPITest >> serviceDefinitions [

Expand All @@ -41,9 +61,10 @@ ConsulServiceDiscoveryPluginAPITest >> serviceDefinitions [
{ #category : #tests }
ConsulServiceDiscoveryPluginAPITest >> setUp [

consulAgentPort := self freeListeningTCPPort.
consulAgent := FakeConsulAgentAPI
configuredBy:
{( #port -> 9998 ).
{( #port -> consulAgentPort ).
( #serverUrl -> self consulAgentLocation ).
( #debugMode -> true )}
on: self.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : #ConsulServiceDiscoveryPluginInteractionTest,
#superclass : #TestCase,
#instVars : [
'consulAgent'
'consulAgent',
'port'
],
#category : #'Stargate-Consul-Tests'
}
Expand All @@ -16,24 +17,19 @@ ConsulServiceDiscoveryPluginInteractionTest >> apiServer [
{ #category : #accessing }
ConsulServiceDiscoveryPluginInteractionTest >> baseUrl [

^ 'http://localhost' asUrl port: self port
]

{ #category : #accessing }
ConsulServiceDiscoveryPluginInteractionTest >> port [

^ 9998
^ 'http://localhost' asUrl port: port
]

{ #category : #running }
ConsulServiceDiscoveryPluginInteractionTest >> setUp [

super setUp.
port := self freeListeningTCPPort.
consulAgent := FakeConsulAgentAPI
configuredBy:
{( #port -> self port ).
( #serverUrl -> self baseUrl ).
( #debugMode -> true )}
{ #port -> port.
#serverUrl -> self baseUrl.
#debugMode -> true }
on: self.
consulAgent start
]
Expand Down
22 changes: 11 additions & 11 deletions source/Stargate-Consul/ConsulServiceDefinitionBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ConsulServiceDefinitionBuilder >> addCheck: aConsulAgentCheck [

| checks |

checks := serviceDefinition at: 'Checks' ifAbsentPut: [ OrderedCollection new ].
checks := serviceDefinition at: #Checks ifAbsentPut: [ OrderedCollection new ].
checks add: aConsulAgentCheck
]

Expand All @@ -55,14 +55,14 @@ ConsulServiceDefinitionBuilder >> addTag: aString [
| tags |

AssertionChecker enforce: [ aString notEmpty ] because: 'A tag cannot be empty'.
tags := serviceDefinition at: 'Tags' ifAbsentPut: [ OrderedCollection new ].
tags := serviceDefinition at: #Tags ifAbsentPut: [ OrderedCollection new ].
tags add: aString
]

{ #category : #configuring }
ConsulServiceDefinitionBuilder >> address: aString [
serviceDefinition at: 'Address' put: aString
ConsulServiceDefinitionBuilder >> address: aString [

serviceDefinition at: #Address put: aString
]

{ #category : #private }
Expand All @@ -77,21 +77,21 @@ ConsulServiceDefinitionBuilder >> assertIsValidPort: aPortNumber [
ConsulServiceDefinitionBuilder >> buildNamed: aServiceName [

AssertionChecker enforce: [ aServiceName notEmpty ] because: 'A service name cannot be empty'.
serviceDefinition at: 'Name' put: aServiceName.
serviceDefinition at: #Name put: aServiceName.
^ NeoJSONObject newFrom: serviceDefinition
]

{ #category : #configuring }
ConsulServiceDefinitionBuilder >> enableTagOverride [

serviceDefinition at: 'EnableTagOverride' put: true
serviceDefinition at: #EnableTagOverride put: true
]

{ #category : #configuring }
ConsulServiceDefinitionBuilder >> identifiedBy: aString [

AssertionChecker enforce: [ aString notEmpty ] because: 'An ID cannot be empty'.
serviceDefinition at: 'ID' put: aString
serviceDefinition at: #ID put: aString
]

{ #category : #initialization }
Expand All @@ -104,14 +104,14 @@ ConsulServiceDefinitionBuilder >> initialize [
{ #category : #configuring }
ConsulServiceDefinitionBuilder >> metadataAt: aKey put: aValue [

serviceDefinition at: 'Meta' at: aKey put: aValue
serviceDefinition at: #Meta at: aKey put: aValue
]

{ #category : #configuring }
ConsulServiceDefinitionBuilder >> port: anInteger [

self assertIsValidPort: anInteger.
serviceDefinition at: 'Port' put: anInteger
serviceDefinition at: #Port put: anInteger
]

{ #category : #configuring }
Expand All @@ -126,7 +126,7 @@ ConsulServiceDefinitionBuilder >> taggedAddressesAt: aTag on: aKey put: aValue [
| taggedAddresses |

taggedAddresses := serviceDefinition
at: 'TaggedAddresses'
at: #TaggedAddresses
ifAbsentPut: [ serviceDefinition species new ].
taggedAddresses at: aTag at: aKey put: aValue
]
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ConsulServiceDiscoveryPlugin >> deregisterFromConsul: serviceDefinition [

deregisterRequest := HttpRequest
put: ( self deregistrationUrlFor: serviceDefinition )
configuredUsing: [ :request | request body json: {} asDictionary ].
configuredUsing: [ :request | request body json: Dictionary new ].
deregisterRequest applyOn: self newHttpClient
]

Expand Down

0 comments on commit 80fb3e0

Please sign in to comment.