From ca96c88f96db5c952211f7b5cd33d8e9f6c0b1c2 Mon Sep 17 00:00:00 2001 From: Benoit Verhaeghe Date: Fri, 14 Jun 2024 15:00:33 +0200 Subject: [PATCH] add test with test resources --- .../GLHModelImporterTest.class.st | 36 ++++++------------- .../GLHModelImporterTestResource.class.st | 32 +++++++++++++++++ .../GLHModelImporter.class.st | 9 ++--- 3 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTestResource.class.st diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTest.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTest.class.st index 5db713a..1a129d6 100644 --- a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTest.class.st +++ b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTest.class.st @@ -13,37 +13,23 @@ Class { #category : #'GitLabHealth-Model-Importer-Tests' } -{ #category : #'class initialization' } -GLHModelImporterTest class >> initialize [ +{ #category : #accessing } +GLHModelImporterTest class >> resources [ - + ^ Array with: GLHModelImporterTestResource ] { #category : #running } -GLHModelImporterTest >> setUp [ +GLHModelImporterTest >> model [ - super setUp. - - "Put here a common initialization logic for tests" - glphModel := GLPHEModel new. - - glphApi := GLPHApi new - privateToken: ''; - baseAPIUrl: 'https://gitlab.com/api/v4'; - yourself. - - since := Date today - 2 day. - - glhImporter := GLPHModelImporter new - glhApi: glphApi; - glhModel: glphModel; - withFiles: false; - withCommitsSince: 0 day; - withCommitDiffs: true. - - glhImporter importGroup: 87194534. + ^ self class resources first current model ] { #category : #tests } -GLHModelImporterTest >> testImport [ +GLHModelImporterTest >> testImportProject [ + + self assert: (self model allWithType: GLHProject) size equals: 1. + self assert: + ((self model allWithType: GLHProject) anySatisfy: [ :project | + project id = 57841283 ]) ] diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTestResource.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTestResource.class.st new file mode 100644 index 0000000..289f59c --- /dev/null +++ b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterTestResource.class.st @@ -0,0 +1,32 @@ +Class { + #name : #GLHModelImporterTestResource, + #superclass : #MooseModelTestResource, + #instVars : [ + 'glphApi', + 'since', + 'glhImporter' + ], + #category : #'GitLabHealth-Model-Importer-Tests' +} + +{ #category : #setup } +GLHModelImporterTestResource >> importModel [ + + model := GLPHEModel new. + + glphApi := GLPHApi new + privateToken: ''; + baseAPIUrl: 'https://gitlab.com/api/v4'; + yourself. + + since := Date today - 2 day. + + glhImporter := GLPHModelImporter new + glhApi: glphApi; + glhModel: model; + withFiles: false; + withCommitsSince: 0 day; + withCommitDiffs: true. + + glhImporter importGroup: 87194534 +] diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 0cb5fe5..2e3d32a 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -31,8 +31,10 @@ GLHModelImporter >> addCommits: commitsList toRepository: aProjectRepository [ { #category : #private } GLHModelImporter >> addGroupResultToModel: groupResult [ - self glhModel add: groupResult. - self glhModel addAll: groupResult projects + self glhModel add: groupResult unless: (self blockEqualityOn: #id). + self glhModel + addAll: groupResult projects + unless: (self blockEqualityOn: #id) ] { #category : #accessing } @@ -524,8 +526,7 @@ GLHModelImporter >> importGroup: aGroupID [ self completeImportProject: project ]. self addGroupResultToModel: groupResult. (self subGroupsOf: aGroupID) do: [ :subGroup | - - groupResult addSubGroup: (self importGroup: subGroup id) ]. + groupResult addSubGroup: (self importGroup: subGroup id) ]. ^ groupResult ]