Skip to content

Commit 54ad97c

Browse files
committed
unit tests added, dev.md and readme.md updated
1 parent 94be85e commit 54ad97c

10 files changed

Lines changed: 209 additions & 63 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "objectscript",
66
"request": "launch",
77
"name": "ObjectScript Debug Class",
8-
"program": "##class(PackageSample.ObjectScript).Test()",
8+
"program": "##class(dc.sample.ObjectScript).Test()",
99
},
1010
{
1111
"type": "objectscript",

.vscode/settings.json

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,17 @@
55
"iris.script": "objectscript"
66
},
77
"objectscript.conn" :{
8+
"active":true,
89
"ns": "IRISAPP",
9-
"username": "_SYSTEM",
10+
"username": "SuperUser",
1011
"password": "SYS",
1112
"docker-compose": {
1213
"service": "iris",
1314
"internalPort": 52773
1415
},
15-
"active": true
16-
},
17-
"sqltools.connections": [
18-
{
19-
"namespace": "IRISAPP",
20-
"connectionMethod": "Server and Port",
21-
"showSystem": false,
22-
"previewLimit": 50,
23-
"server": "localhost",
24-
"port": 32770,
25-
"askForPassword": false,
26-
"driver": "InterSystems IRIS",
27-
"name": "objectscript-docker",
28-
"username": "_SYSTEM",
29-
"password": "SYS"
30-
}
31-
]
16+
"links" :{
17+
"UnitTest Portal" :"${serverUrl}/csp/sys/%25UnitTest.Portal.Home.cls?$NAMESPACE=IRISAPP"
18+
}
19+
}
3220

3321
}

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ ARG IMAGE=intersystemsdc/iris-community:2020.2.0.204.0-zpm
44
ARG IMAGE=intersystemsdc/irishealth-community:2020.3.0.200.0-zpm
55
ARG IMAGE=intersystemsdc/iris-community:2020.3.0.221.0-zpm
66
ARG IMAGE=intersystemsdc/iris-community:2020.4.0.547.0-zpm
7+
ARG IMAGE=containers.intersystems.com/intersystems/iris:2021.1.0.215.0
78
ARG IMAGE=intersystemsdc/iris-community
89
FROM $IMAGE
910

1011
USER root
11-
## add git
12-
RUN apt update && apt-get -y install git
1312

1413
WORKDIR /opt/irisbuild
1514
RUN chown ${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} /opt/irisbuild

README.md

Lines changed: 131 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
[![Gitter](https://img.shields.io/badge/Available%20on-Intersystems%20Open%20Exchange-00b2a9.svg)](https://openexchange.intersystems.com/package/intersystems-iris-dev-template)
22
[![Quality Gate Status](https://community.objectscriptquality.com/api/project_badges/measure?project=intersystems_iris_community%2Fintersystems-iris-dev-template&metric=alert_status)](https://community.objectscriptquality.com/dashboard?id=intersystems_iris_community%2Fintersystems-iris-dev-template)
33
[![Reliability Rating](https://community.objectscriptquality.com/api/project_badges/measure?project=intersystems_iris_community%2Fintersystems-iris-dev-template&metric=reliability_rating)](https://community.objectscriptquality.com/dashboard?id=intersystems_iris_community%2Fintersystems-iris-dev-template)
4-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat&logo=AdGuard)](LICENSE)
54

5+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat&logo=AdGuard)](LICENSE)
66
# intersystems-iris-dev-template
7-
This is a basic template to develop with InterSystems IRIS
7+
This is a basic template of a dev environment to develop with InterSystems IRIS ObjectScript
88

99
## Description
10-
* The template uses InterSystems IRIS Community Edition running in a docker container
11-
* It uses ZPM Package Manager to load InterSystems ObjectScript
12-
* It creates a Namespace IRISAPP without interoperability Enabled
13-
* It is designed to develop with Package First paradigm
10+
The idea of the repository is to provide a read-to-go dev environment if one needs to code InterSystems ObjectScript.
11+
* The template runs InterSystems IRIS Community Edition running in a docker container
12+
* It creates a fresh new namespace and database IRISAPP
13+
* It loads the ObjectScript code into IRISAPP database using Package Manager
14+
* It suggests development with 'Package First' paradigm. Watch the video](https://www.youtube.com/watch?v=havPyPbUj1I)
15+
* Provides unittests environment: sample unittests, tests module enablement
1416

1517
## Usage
1618
start a new dev repository with InterSystems IRIS using this one as a template.
@@ -19,70 +21,169 @@ Once you clone the new repo on your laptop and open the VSCode with installed In
1921
## Prerequisites
2022
Make sure you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker desktop](https://www.docker.com/products/docker-desktop) installed.
2123

22-
## Installation
24+
## Installation
2325
Clone/git pull the repo into any local directory
2426
```
2527
$ git clone https://github.com/intersystems-community/intersystems-iris-dev-template.git
2628
```
2729

28-
Open the terminal in this directory and run:
30+
Open the terminal in this directory and call the command to build and run InterSystems IRIS in container:
2931

3032
```
31-
$ docker-compose build
33+
$ docker-compose up -d
3234
```
3335

34-
3. Run the IRIS container with your project:
35-
36+
To open IRIS Terminal do:
3637
```
37-
$ docker-compose up -d
38+
$ docker-compose exec iris iris session iris -U IRISAPP
39+
IRISAPP>
3840
```
3941

40-
## How to Test it
41-
42-
Open IRIS terminal:
42+
To exit the terminal, do any of the following:
43+
```
44+
Enter HALT or H (not case-sensitive)
45+
```
46+
## What does it do
47+
THe sample repository contains two simplest examples of ObjectScript classes: ObjectScript method that returns value and method that creates a persistent record.
48+
1.
49+
Open IRIS terminal and run the ObjectScript Test() method to see if runs the script and returns values from IRIS:
4350

4451
```
4552
$ docker-compose exec iris iris session iris -U IRISAPP
4653
IRISAPP>write ##class(dc.sample.ObjectScript).Test()
54+
It works!
55+
42
4756
```
4857

49-
To exit the terminal, do any of the following:
58+
59+
60+
2.
61+
Class dc.sample.PersistentClass contains a method CreateRecord that creates an object with one property Test and returns its id.
62+
Open IRIS terminal and run:
5063
```
51-
Enter HALT or H (not case-sensitive)
64+
IRISAPP>write ##class(dc.sample.PersistentClass).CreateRecord(.id)
65+
1
66+
IRISAPP>write id
67+
1
5268
```
69+
In your case the value of id could be different. And it will be different with every call of the method.
5370

54-
## How to start coding
71+
You can check whether the record exists and try to right the property of the object by its id.
72+
```
73+
IRISAPP>write ##class(dc.sample.PersistentClass).ReadProperty(id)
74+
Test string
75+
```
76+
77+
78+
## How to start the development
5579
This repository is ready to code in VSCode with ObjectScript plugin.
5680
Install [VSCode](https://code.visualstudio.com/), [Docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) and [ObjectScript](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript) plugin and open the folder in VSCode.
5781
Open /src/cls/PackageSample/ObjectScript.cls class and try to make changes - it will be compiled in running IRIS docker container.
5882
![docker_compose](https://user-images.githubusercontent.com/2781759/76656929-0f2e5700-6547-11ea-9cc9-486a5641c51d.gif)
5983

6084
Feel free to delete PackageSample folder and place your ObjectScript classes in a form
61-
/src/Package/Classname.cls
85+
/src/organisation/package/Classname.cls
6286
[Read more about folder setup for InterSystems ObjectScript](https://community.intersystems.com/post/simplified-objectscript-source-folder-structure-package-manager)
87+
and her on the [naming convention]()
88+
89+
## running unittests
90+
The template contains to test classes: TestObjectScript.cls and TestPersistentClass.cls
91+
To run the unittests we can use Package Manager environment.
92+
```
93+
IRISAPP>zpm
94+
95+
=============================================================================
96+
|| Welcome to the Package Manager Shell (ZPM). ||
97+
|| Enter q/quit to exit the shell. Enter ?/help to view available commands ||
98+
=============================================================================
99+
zpm:IRISAPP>load /irisrun/repo
100+
101+
[dc-sample-template] Reload START (/irisrun/repo/)
102+
[dc-sample-template] Reload SUCCESS
103+
[dc-sample-template] Module object refreshed.
104+
[dc-sample-template] Validate START
105+
[dc-sample-template] Validate SUCCESS
106+
[dc-sample-template] Compile START
107+
[dc-sample-template] Compile SUCCESS
108+
[dc-sample-template] Activate START
109+
[dc-sample-template] Configure START
110+
[dc-sample-template] Configure SUCCESS
111+
[dc-sample-template] MakeDeployed START
112+
[dc-sample-template] MakeDeployed SUCCESS
113+
[dc-sample-template] Activate SUCCESS
114+
zpm:IRISAPP>test dc-sample-template
115+
116+
[dc-sample-template] Reload START (/irisrun/repo/)
117+
[dc-sample-template] Reload SUCCESS
118+
[dc-sample-template] Module object refreshed.
119+
[dc-sample-template] Validate START
120+
[dc-sample-template] Validate SUCCESS
121+
[dc-sample-template] Compile START
122+
[dc-sample-template] Compile SUCCESS
123+
[dc-sample-template] Activate START
124+
[dc-sample-template] Configure START
125+
[dc-sample-template] Configure SUCCESS
126+
[dc-sample-template] MakeDeployed START
127+
[dc-sample-template] MakeDeployed SUCCESS
128+
[dc-sample-template] Activate SUCCESS
129+
[dc-sample-template] Test STARTIt works!
130+
131+
Use the following URL to view the result:
132+
http://172.28.0.2:52773/csp/sys/%25UnitTest.Portal.Indices.cls?Index=1&$NAMESPACE=IRISAPP
133+
All PASSED
134+
135+
[dc-sample-template] Test SUCCESS
136+
zpm:IRISAPP>
137+
```
138+
In case of test errors you can check it back in the UnitTest portal, that can be easily opened via ObjectScript menu in VSCode:
139+
![vscvode unittest](https://user-images.githubusercontent.com/2781759/152678943-7d9d9696-e26a-449f-b1d7-f924528c8e3a.png)
63140

64-
The script in Installer.cls will import everything you place under /src into IRIS.
141+
## What else is inside the repository
65142

143+
### .github folder
144+
it contains to github actions workflows:
145+
1. github-registry.yml
146+
Once changes pushed to the repo, the action builds the docker image on Github side and pushes the image to Github registry that can be very convenient to further cloud deployement, e.g. kubernetes.
147+
2. objectscript-qaulity.yml
148+
with every push to master or main branch the workflow launches the repo test on objectscript issues with Objectscript Quality tool, [see the examples](https://community.objectscriptquality.com/projects?sort=-analysis_date). This works if the repo is open-source only.
66149

67-
## What's inside the repository
150+
Both workflows are repo agnostic: so they work with any repository where they exist.
68151

69-
### Dockerfile
152+
### .vscode folder
153+
it contains to files to setup vscode environment:
154+
#### .vscode/settings.json
70155

71-
The simplest dockerfile which starts IRIS and imports code from /src folder into it.
72-
Use the related docker-compose.yml to easily setup additional parametes like port number and where you map keys and host folders.
156+
Settings file to let you immedietly code in VSCode with [VSCode ObjectScript plugin](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript))
157+
158+
#### .vscode/launch.json
159+
Config file if you want to debug with VSCode ObjectScript
73160

74161

75162
### src folder
163+
contains source files.
76164
src/iris contains InterSystems IRIS Objectscript code
77-
src/java containers Java code
78-
src/python - python code, etc.
79165

166+
### tests folder
167+
contains unittests for the ObjectScript classes
80168

81-
### .vscode/settings.json
169+
### dev.md
170+
contains a set of useful commands that will help during the development
82171

83-
Settings file to let you immedietly code in VSCode with [VSCode ObjectScript plugin](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript))
172+
### docker-compose.yml
173+
a docker engine helper file to manage images building and rule ports mapping an the host to container folders(volumes) mapping
174+
### Dockerfile
175+
176+
The simplest dockerfile which starts IRIS and imports code from /src folder into it.
177+
Use the related docker-compose.yml to easily setup additional parametes like port number and where you map keys and host folders.
178+
179+
180+
### iris.script
181+
contains objectscript commands that are feeded to iris during the image building
182+
183+
### module.xml
184+
IPM Module's description of the code in the repository.
185+
It describes what is loaded with the method, how it is being tested and what apps neeed to be created, what files need to be copied.
84186

85-
### .vscode/launch.json
86-
Config file if you want to debug with VSCode ObjectScript
87187

88188
[Read about all the files in this artilce](https://community.intersystems.com/post/dockerfile-and-friends-or-how-run-and-collaborate-objectscript-projects-intersystems-iris)
189+

dev.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ docker system prune -f
99
docker rm -f $(docker ps -qa)
1010
```
1111

12-
1312
## build container with no cache
1413
```
1514
docker-compose build --no-cache --progress=plain
@@ -24,6 +23,13 @@ docker-compose up -d
2423
docker-compose exec iris iris session iris -U IRISAPP
2524
```
2625

26+
## map iris key from Mac home directory to IRIS in container
27+
- ~/iris.key:/usr/irissys/mgr/iris.key
28+
29+
## install git in the docker image
30+
## add git
31+
RUN apt update && apt-get -y install git
32+
2733
## install docker-compose
2834
```
2935
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
@@ -62,10 +68,19 @@ zn "%SYS" \
6268
write "Web application "_webName_" has been created!",!
6369
```
6470

65-
zw ##class(community.csvgen).GenerateFromURL("https://github.com/h2oai/h2o-tutorials/raw/master/h2o-world-2017/automl/data/product_backorders.csv")
6671

67-
Import directory with IRIS code
6872

6973
```
7074
do $SYSTEM.OBJ.ImportDir("/opt/irisbuild/src",, "ck")
71-
```
75+
```
76+
77+
78+
### run tests described in the module
79+
80+
IRISAPP>zpm
81+
IRISAPP:zpm>load /irisrun/repo
82+
IRISAPP:zpm>test package-name
83+
84+
### install ZPM with one line
85+
// Install ZPM
86+
set $namespace="%SYS", name="DefaultSSL" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name) set url="https://pm.community.intersystems.com/packages/zpm/latest/installer" Do ##class(%Net.URLParser).Parse(url,.comp) set ht = ##class(%Net.HttpRequest).%New(), ht.Server = comp("host"), ht.Port = 443, ht.Https=1, ht.SSLConfiguration=name, st=ht.Get(comp("path")) quit:'st $System.Status.GetErrorText(st) set xml=##class(%File).TempFilename("xml"), tFile = ##class(%Stream.FileBinary).%New(), tFile.Filename = xml do tFile.CopyFromAndSave(ht.HttpResponse.Data) do ht.%Close(), $system.OBJ.Load(xml,"ck") do ##class(%File).Delete(xml)

module.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Export generator="Cache" version="25">
3-
<Document name="intersystems-iris-template.ZPM">
3+
<Document name="dc-sample-template.ZPM">
44
<Module>
5-
<Name>intersystems-iris-template</Name>
5+
<Name>dc-sample-template</Name>
66
<Version>1.1.0</Version>
7+
<Description>A basic module template for InterSystems ObjectScript with Unittests</Description>
78
<Packaging>module</Packaging>
89
<SourcesRoot>src/iris</SourcesRoot>
910
<Resource Name="dc.sample.PKG"/>
11+
<UnitTest Name="/tests" Package="dc.sample.unittests" Phase="test"/>
1012
</Module>
1113
</Document>
1214
</Export>

src/iris/dc/sample/ObjectScript.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Class dc.sample.ObjectScript
33

44
ClassMethod Test() As %Status
55
{
6-
set a=42
7-
return "It works!"
6+
set a=42
7+
write "It works!",!
8+
return 42
89
}
910

1011
}

src/iris/dc/sample/PersistentClass.cls

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ Class dc.sample.PersistentClass Extends %Persistent
33

44
Property Test As %VarString;
55

6-
ClassMethod CreateRecord() As %Status
6+
ClassMethod CreateRecord(ByRef id As %Integer) As %Status
77
{
8-
s objPC=..%New()
9-
s objPC.Test="Test string"
10-
return objPC.%Save()
8+
set sc=$$$OK
9+
set objPC=..%New()
10+
set objPC.Test="Test string"
11+
set sc=objPC.%Save()
12+
set id=objPC.%Id()
13+
return sc
14+
}
15+
16+
/// opens the record by id and reads its property
17+
ClassMethod ReadProperty(id As %Integer) As %Status
18+
{
19+
Set sc = $$$OK
20+
#dim obj as dc.sample.PersistentClass
21+
set obj=..%OpenId(id,,.sc)
22+
if $ISOBJECT(obj) write obj.Test
23+
Return sc
1124
}
1225

1326
Storage Default
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Class dc.sample.unittests.TestObjectScript Extends %UnitTest.TestCase
2+
{
3+
4+
Method Test42()
5+
{
6+
Set tExpected=42
7+
set tResults= ##class(dc.sample.ObjectScript).Test()
8+
Do $$$AssertEquals(tResults,tExpected,tExpected_" = "_tResults)
9+
}
10+
11+
}

0 commit comments

Comments
 (0)