Skip to content

Commit

Permalink
Refactor HTTP Bin and Memcached hostname access so it can be configur…
Browse files Browse the repository at this point in the history
…ed on CI
  • Loading branch information
gcotelli committed Feb 27, 2024
1 parent 53cec0f commit 54d19fc
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ BaselineOfSuperluminal >> setUpTestPackages: spec [
group: 'Tests' with: 'Superluminal-Model-Tests-Extensions'.
spec
package: 'Superluminal-Model-Tests'
with: [ spec requires: #('Superluminal-Model-Extensions' 'Hyperspace-SUnit') ];
with: [ spec requires: #('Superluminal-Model-Extensions' 'Hyperspace-SUnit' 'Superluminal-SUnit-Model') ];
group: 'Tests' with: 'Superluminal-Model-Tests'.
spec
package: 'Superluminal-RESTfulAPI-Tests'
Expand Down
11 changes: 2 additions & 9 deletions source/Superluminal-Model-Tests/HttpRequestTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A NapTest is a test class for testing the behavior of Nap
"
Class {
#name : 'HttpRequestTest',
#superclass : 'TestCase',
#superclass : 'SuperluminalTest',
#category : 'Superluminal-Model-Tests-Core',
#package : 'Superluminal-Model-Tests',
#tag : 'Core'
Expand Down Expand Up @@ -43,14 +43,7 @@ HttpRequestTest >> fullNameVersion1dot0dot0MediaType [
{ #category : 'private' }
HttpRequestTest >> httpbinLocation [

| hostname |

hostname := LanguagePlatform current os
environmentAt: 'CI_HTTPBIN_HOSTNAME'
ifPresent: [ :hostnameInVariable | hostnameInVariable ]
ifAbsent: [ 'localhost' ].

^ 'http://<1s>/anything' expandMacrosWith: hostname
^ 'http://<1s>/anything' expandMacrosWith: self httpbinHostname
]

{ #category : 'private' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : 'CacheRepositoryTest',
#superclass : 'TestCase',
#superclass : 'SuperluminalTest',
#instVars : [
'currentDateTime',
'repository',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Class {

{ #category : 'running' }
DistributedMemoryBasedExpiringCacheTest >> setUpExpiringCache [

| memcached |
memcached := MDCacheClient onServers: {'127.0.0.1:11211'}.
cache := ExpiringCache persistingTo: (DistributedMemoryCacheRepository using: currentTimeProvider persistingTo: memcached).

memcached := MDCacheClient onServers: { '<1s>:11211' expandMacrosWith: self memcachedHostname }.
cache := ExpiringCache persistingTo:
( DistributedMemoryCacheRepository using: currentTimeProvider persistingTo: memcached )
]

{ #category : 'private' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Class {
DistributedMemoryCacheRepositoryTest >> setUpRepository [

repository := DistributedMemoryCacheRepository
using: currentTimeProvider
persistingTo: ( MDCacheClient onServers: {'127.0.0.1:11211'} )
using: currentTimeProvider
persistingTo:
( MDCacheClient onServers:
{ '<1s>:11211' expandMacrosWith: self memcachedHostname } )
]

{ #category : 'running' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ An ExpiringCacheTest is a test class for testing the behavior of ExpiringCache
"
Class {
#name : 'ExpiringCacheTest',
#superclass : 'TestCase',
#superclass : 'SuperluminalTest',
#instVars : [
'currentDateTime',
'cache',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ Class {
#package : 'Superluminal-RESTfulAPI-Tests'
}

{ #category : 'running' }
{ #category : 'accessing' }
RESTfulAPIClientCachingOnDistributedMemoryTest >> apiClient [

^ RESTfulAPIClient
buildingHttpClientWith: [ self httpClient ]
cachingIn: ( ExpiringCache onDistributedMemoryAt: {'127.0.0.1:11211'} )
buildingHttpClientWith: [ self httpClient ]
cachingIn: (ExpiringCache onDistributedMemoryAt:
{ ('<1s>:11211' expandMacrosWith: self memcachedHostname) })
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A RESTfulAPIClientTest is a test class for testing the behavior of RESTfulAPICli
"
Class {
#name : 'RESTfulAPIClientIntegrationTest',
#superclass : 'TestCase',
#superclass : 'SuperluminalTest',
#instVars : [
'apiClient'
],
Expand All @@ -26,7 +26,8 @@ RESTfulAPIClientIntegrationTest >> httpbinCacheLocation [
{ #category : 'private' }
RESTfulAPIClientIntegrationTest >> httpbinLocation [

^ 'http://localhost' asAbsoluteUrl
^ ('http://<1s>' expandMacrosWith: self httpbinHostname)
asAbsoluteUrl
]

{ #category : 'private' }
Expand Down
25 changes: 13 additions & 12 deletions source/Superluminal-SUnit-Model/APIClientTest.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
Class {
#name : #APIClientTest,
#superclass : #TestCase,
#name : 'APIClientTest',
#superclass : 'SuperluminalTest',
#instVars : [
'teachableHttpClient'
],
#category : #'Superluminal-SUnit-Model'
#category : 'Superluminal-SUnit-Model',
#package : 'Superluminal-SUnit-Model'
}

{ #category : #testing }
{ #category : 'testing' }
APIClientTest class >> isAbstract [

^ self = APIClientTest
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> configure: httpClient toRespondWith: response [

httpClient whenSend: #response return: response
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> configure: httpClient toRespondWithAll: responses [

| responseQueue |
Expand All @@ -28,25 +29,25 @@ APIClientTest >> configure: httpClient toRespondWithAll: responses [
httpClient whenSend: #response evaluate: [ responseQueue removeFirst ]
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> configureHttpClientToRespondWith: response [

self configure: teachableHttpClient toRespondWith: response
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> configureHttpClientToRespondWithAll: responses [

self configure: teachableHttpClient toRespondWithAll: responses
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> httpClient [

^ teachableHttpClient
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> jsonOkResponseWith: jsonPayload [

^ ZnResponse
Expand All @@ -58,7 +59,7 @@ APIClientTest >> jsonOkResponseWith: jsonPayload [
otherwise: [ NeoJSONWriter toStringPretty: jsonPayload ] ) )
]

{ #category : #'private - utility' }
{ #category : 'private - utility' }
APIClientTest >> newTeachableHttpClient [

^ Teachable new
Expand All @@ -76,7 +77,7 @@ APIClientTest >> newTeachableHttpClient [
yourself
]

{ #category : #running }
{ #category : 'running' }
APIClientTest >> setUp [

super setUp.
Expand Down
30 changes: 30 additions & 0 deletions source/Superluminal-SUnit-Model/SuperluminalTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Class {
#name : 'SuperluminalTest',
#superclass : 'TestCase',
#category : 'Superluminal-SUnit-Model',
#package : 'Superluminal-SUnit-Model'
}

{ #category : 'testing' }
SuperluminalTest class >> isAbstract [

^ self = SuperluminalTest
]

{ #category : 'accessing' }
SuperluminalTest >> httpbinHostname [

^ LanguagePlatform current os
environmentAt: 'CI_HTTPBIN_HOSTNAME'
ifPresent: [ :hostnameInVariable | hostnameInVariable ]
ifAbsent: [ 'localhost' ]
]

{ #category : 'accessing' }
SuperluminalTest >> memcachedHostname [

^ LanguagePlatform current os
environmentAt: 'CI_MEMCACHED_HOSTNAME'
ifPresent: [ :hostnameInVariable | hostnameInVariable ]
ifAbsent: [ '127.0.0.1' ]
]
2 changes: 1 addition & 1 deletion source/Superluminal-SUnit-Model/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Superluminal-SUnit-Model' }
Package { #name : 'Superluminal-SUnit-Model' }

0 comments on commit 54d19fc

Please sign in to comment.