Skip to content

Commit

Permalink
Merge pull request #46 from zweidenker/hunting-self-exception
Browse files Browse the repository at this point in the history
cleaned up mess done while fixinf delete bug. Refactored tests to the…
  • Loading branch information
noha authored Mar 23, 2020
2 parents a7b59e4 + 98db1f8 commit c369c32
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 100 deletions.
29 changes: 29 additions & 0 deletions source/SnapDump-Core-Tests/ExceptionMock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : #ExceptionMock,
#superclass : #Object,
#instVars : [
'snapshot'
],
#category : #'SnapDump-Core-Tests'
}

{ #category : #accessing }
ExceptionMock class >> snapshot: aSnapshot [
^ self new
snapshot: aSnapshot
]

{ #category : #converting }
ExceptionMock >> asSnapshot [
^ snapshot
]

{ #category : #accessing }
ExceptionMock >> description [
^ 'an exception mock'
]

{ #category : #accessing }
ExceptionMock >> snapshot: anObject [
snapshot := anObject
]
44 changes: 19 additions & 25 deletions source/SnapDump-Core-Tests/SDCoreTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Class {
}

{ #category : #tests }
SDCoreTests >> getDummySnapshotFromClient [
SDCoreTests >> getDummySnapshotFromClient: aString [
| snap |
snap := (client
snapshotWithId: self dummySnapshotId project: self projectNameForTests version: self versionStringForTests) .
snapshotWithId: aString project: self projectNameForTests version: self versionStringForTests) .
^ snap
]

{ #category : #tests }
SDCoreTests >> getDummySnapshotFromClient: aString [
| snap |
snap := (client
snapshotWithId: aString project: self projectNameForTests version: self versionStringForTests) .
^ snap
SDCoreTests >> roundtripSnapshot [
| s |
s := self createSimpleSnapshot.
^ self getDummySnapshotFromClient: s snapshotId.

]

{ #category : #accessing }
Expand Down Expand Up @@ -103,9 +103,8 @@ SDCoreTests >> testProjectVersions [
{ #category : #tests }
SDCoreTests >> testReadSnapshotFuelDump [

| snapshot context fuel s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot context fuel |
snapshot := self roundtripSnapshot.
fuel := snapshot newReader fuelDumpStreamDo: [ :stream :length |
stream upToEnd ].

Expand All @@ -116,18 +115,16 @@ SDCoreTests >> testReadSnapshotFuelDump [
{ #category : #tests }
SDCoreTests >> testReadSnapshotMeta [

| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot |
snapshot := self roundtripSnapshot.
self assert: snapshot project name = 'TestProject'
]

{ #category : #tests }
SDCoreTests >> testReadSnapshotStackTrace [

| snapshot string stack s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot string stack |
snapshot := self roundtripSnapshot.
self assert: snapshot project name = 'TestProject'.

stack := snapshot newReader stackTraceStreamDo: [ :stream :length |
Expand All @@ -154,9 +151,8 @@ SDCoreTests >> testRemoveProjectVersion [
{ #category : #tests }
SDCoreTests >> testRemoveSnapshot [

| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot |
snapshot := self roundtripSnapshot.
self assert: snapshot className equals: 'Object'.
self
shouldnt: [ snapshot remove ]
Expand All @@ -166,9 +162,8 @@ SDCoreTests >> testRemoveSnapshot [

{ #category : #tests }
SDCoreTests >> testRemoveVersion [
| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot |
snapshot := self roundtripSnapshot.
self assert: snapshot className equals: 'Object'.
snapshot version remove.
self assert: client projects isEmpty
Expand All @@ -195,9 +190,8 @@ SDCoreTests >> testSetup [
{ #category : #tests }
SDCoreTests >> testSnapshot [

| snapshot s |
s := self createSimpleSnapshot.
snapshot := self getDummySnapshotFromClient: s snapshotId.
| snapshot |
snapshot := self roundtripSnapshot.
self assert: snapshot className equals: 'Object'
]

Expand Down
23 changes: 4 additions & 19 deletions source/SnapDump-Core-Tests/SDTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,8 @@ SDTests >> createSimpleSnapshot [
{ #category : #'as yet unclassified' }
SDTests >> dummyContextSnapshot [

| snapshot |
snapshot := SDSnapshot dummyContextSnapshot.
"snapshot exception instVarNamed: #id put: self dummyExceptionId."
snapshot
"instVarNamed: #exceptionId put: self dummyExceptionId;"
"instVarNamed: #snapshotId put: self dummySnapshotId;"
yourself.
^ snapshot
]
^ SDSnapshot dummyContextSnapshot.

{ #category : #tests }
SDTests >> dummyExceptionId [
^ '292310505b9f7c1493d42c91693b6222e09f5ec6cd1e16d18d1b7ec1570d8a03'
]

{ #category : #tests }
SDTests >> dummySnapshotId [
^ 'a946512aec0333fecaa26fbb58131ffec168e43b8f8e56999603005c94e39c92'
]

{ #category : #tests }
Expand Down Expand Up @@ -68,11 +52,12 @@ SDTests >> setUp [

{ #category : #tests }
SDTests >> snapshotMock [
| mock |
"| mock |
mock := Mock new.
mock stub asSnapshot
willReturn: self dummyContextSnapshot.
^ mock
^ mock"
^ ExceptionMock snapshot: self dummyContextSnapshot

]

Expand Down
95 changes: 39 additions & 56 deletions source/SnapDump-Server-Tests/SDHTTPTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,27 @@ SDHTTPTests >> apiVersionedUri [
^ self apiUri / SDSnapshot apiVersion
]

{ #category : #tests }
SDHTTPTests >> dummySnapshotUrl [
^ (self apiVersionedUri /#projects / self projectNameForTests / #versions / self versionStringForTests / #exceptions / self dummyExceptionId / #snapshots / self dummySnapshotId)
]

{ #category : #tests }
SDHTTPTests >> dummySnapshotUrl: aSnapshot [
^ (self apiVersionedUri /#projects / self projectNameForTests / #versions / self versionStringForTests / #exceptions / self dummyExceptionId / #snapshots / aSnapshot snapshotId)
]

{ #category : #tests }
SDHTTPTests >> dummySnapshotUrlWithoutProject [
^ self apiVersionedUri
/ #snapshots / self dummySnapshotId

" #projects / self projectNameForTests / #versions
/ self versionStringForTests / #exceptions / self dummyExceptionId"
]

{ #category : #accessing }
SDHTTPTests >> randomPort [
^ port ifNil: [
port := 27000 + 1000 atRandom ]
]

{ #category : #tests }
SDHTTPTests >> roundtripSnapshot [
"create, store and retrieve snapshot to be able to test for a
fetched snapshot"
| snapshot response |
snapshot := self createSimpleSnapshot.
response := ZnClient new
url: (self urlForSnapshot: snapshot);
get;
response.
self assert: response isSuccess.
^ (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .

]

{ #category : #initialization }
SDHTTPTests >> selfIP [
^ NetNameResolver stringFromAddress: (NetNameResolver addressForName: NetNameResolver localHostName)
Expand Down Expand Up @@ -74,7 +70,7 @@ SDHTTPTests >> testInternalServerError [
| response snapshot |
server znServer debugMode: false.
response := ZnClient new
url: self dummySnapshotUrl;
url: (self urlForTestVersion / #exceptions / #foo / #snapshots / #bar);
entity: (ZnByteArrayEntity bytes: '{bogus ;json' asByteArray);
put;
response.
Expand All @@ -93,7 +89,7 @@ SDHTTPTests >> testProject [
| response project |
self createSimpleSnapshot.
response := ZnClient new
url: self apiVersionedUri / #projects / #TestProject;
url: self urlForTestProject;
get;
response.
self assert: response isSuccess.
Expand Down Expand Up @@ -171,7 +167,7 @@ SDHTTPTests >> testSnapshotDelete [
| response snapshot |
snapshot := self createSimpleSnapshot.
response := ZnClient new
url: (self dummySnapshotUrl: snapshot) ;
url: (self urlForSnapshot: snapshot) ;
delete;
response.
self assert: response isSuccess.
Expand All @@ -180,7 +176,7 @@ SDHTTPTests >> testSnapshotDelete [

{ #category : #tests }
SDHTTPTests >> testSnapshotEmptyVersion [
| response snap |

handler version: ('').
"reporting empty version should not be allowed"
self should: [self createSimpleSnapshot] raise: NotFound.
Expand All @@ -194,7 +190,7 @@ SDHTTPTests >> testSnapshotGet [
| response snapshot s |
s := self createSimpleSnapshot.
response := ZnClient new
url: (self dummySnapshotUrl: s);
url: (self urlForSnapshot: s);
get;
response.
self assert: response isSuccess.
Expand All @@ -203,47 +199,19 @@ SDHTTPTests >> testSnapshotGet [

]

{ #category : #tests }
SDHTTPTests >> testSnapshotGetById [
| response |
self createSimpleSnapshot.
response := ZnClient new
url: self dummySnapshotUrlWithoutProject ;
get;
response.
"this call should not exist"
self assert: response isError.
self assert: response code = 404.

]

{ #category : #tests }
SDHTTPTests >> testSnapshotGetContext [
| response snapshot context s |
s := self createSimpleSnapshot.
response := ZnClient new
url: (self dummySnapshotUrl: s) ;
get;
response.
self assert: response isSuccess.
snapshot := (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .
self assert: snapshot snapshotId equals: s snapshotId.
| snapshot context |
snapshot := self roundtripSnapshot.
context := FLMaterializer materializeFromByteArray: (self store snapshotDumpFor: snapshot).
self assert: (context isKindOf: Context).
self assert: context receiver = 'TestString'
]

{ #category : #tests }
SDHTTPTests >> testSnapshotGetStackTrace [
| response snapshot stackTrace s |
s := self createSimpleSnapshot.
response := ZnClient new
url: (self dummySnapshotUrl: s);
get;
response.
self assert: response isSuccess.
snapshot := (NeoJSONReader on: response contents readStream) nextAs: SDSnapshot .
self assert: snapshot snapshotId equals: s snapshotId.
| snapshot stackTrace |
snapshot := self roundtripSnapshot.
stackTrace := self store snapshotStackFor: snapshot.
self assert: (stackTrace includesSubstring: 'ByteString(Object)>>printStringLimitedTo:
Receiver: ''TestString'''
Expand Down Expand Up @@ -307,3 +275,18 @@ SDHTTPTests >> testVersionList [
self assert: (list first at: 'string') equals: '0.1'

]

{ #category : #tests }
SDHTTPTests >> urlForSnapshot: aSnapshot [
^ (self urlForTestVersion / #exceptions / aSnapshot exceptionId / #snapshots / aSnapshot snapshotId)
]

{ #category : #tests }
SDHTTPTests >> urlForTestProject [
^ self apiVersionedUri /#projects / self projectNameForTests
]

{ #category : #tests }
SDHTTPTests >> urlForTestVersion [
^ self urlForTestProject / #versions / self versionStringForTests
]

0 comments on commit c369c32

Please sign in to comment.