22
33import * as core from "@actions/core" ;
44import * as http from "@actions/http-client" ;
5+ import * as httpjs from "http" ;
6+ import * as net from 'net' ;
57import * as tc from "@actions/tool-cache" ;
68import * as matlab from "./matlab" ;
79import * as script from "./script" ;
810
9- jest . mock ( "./script" )
11+ jest . mock ( "./script" ) ;
12+ jest . mock ( "http" ) ;
13+ jest . mock ( "net" ) ;
1014jest . mock ( "@actions/core" ) ;
1115jest . mock ( "@actions/http-client" ) ;
1216jest . mock ( "@actions/tool-cache" ) ;
@@ -18,9 +22,10 @@ afterEach(() => {
1822describe ( "matlab tests" , ( ) => {
1923 const release = {
2024 name : "r2022b" ,
21- version : "9.13.0 " ,
22- update : "latest " ,
25+ version : "2022.2.999 " ,
26+ update : "" ,
2327 }
28+ const platform = "linux" ;
2429 describe ( "toolcacheLocation" , ( ) => {
2530 let findMock : jest . Mock < any , any > ;
2631 let cacheFileMock : jest . Mock < any , any > ;
@@ -34,14 +39,14 @@ describe("matlab tests", () => {
3439
3540 it ( "returns toolpath if in toolcache" , async ( ) => {
3641 findMock . mockReturnValue ( "/opt/hostedtoolcache/matlab/r2022b" ) ;
37- await expect ( matlab . makeToolcacheDir ( release ) ) . resolves . toMatchObject ( [ "/opt/hostedtoolcache/matlab/r2022b" , true ] ) ;
42+ await expect ( matlab . makeToolcacheDir ( release , platform ) ) . resolves . toMatchObject ( [ "/opt/hostedtoolcache/matlab/r2022b" , true ] ) ;
3843 expect ( infoMock ) . toHaveBeenCalledTimes ( 1 ) ;
3944 } ) ;
4045
4146 it ( "creates cache and returns new path if not in toolcache" , async ( ) => {
4247 findMock . mockReturnValue ( "" ) ;
4348 cacheFileMock . mockReturnValue ( "/opt/hostedtoolcache/matlab/r2022b" ) ;
44- await expect ( matlab . makeToolcacheDir ( release ) ) . resolves . toMatchObject ( [ "/opt/hostedtoolcache/matlab/r2022b" , false ] ) ;
49+ await expect ( matlab . makeToolcacheDir ( release , platform ) ) . resolves . toMatchObject ( [ "/opt/hostedtoolcache/matlab/r2022b" , false ] ) ;
4550 } )
4651 } ) ;
4752
@@ -78,18 +83,14 @@ describe("matlab tests", () => {
7883 } ) ;
7984
8085 describe ( "getReleaseInfo" , ( ) => {
86+ let infoMock : jest . Mock < any , any > ;
8187 beforeEach ( ( ) => {
88+ infoMock = core . info as jest . Mock ;
8289 // Mock MATLABReleaseInfo response from http client
83- jest . spyOn ( http . HttpClient . prototype , 'getJson ' ) . mockImplementation ( async ( ) => {
90+ jest . spyOn ( http . HttpClient . prototype , 'get ' ) . mockImplementation ( async ( ) => {
8491 return {
85- statusCode : 200 ,
86- result : {
87- latest : 'r2022b' ,
88- version : {
89- r2022b : '9.13.0' ,
90- }
91- } ,
92- headers : { }
92+ message : new httpjs . IncomingMessage ( new net . Socket ( ) ) ,
93+ readBody : ( ) => { return Promise . resolve ( "r2022b" ) }
9394 } ;
9495 } )
9596 } ) ;
@@ -102,28 +103,47 @@ describe("matlab tests", () => {
102103 expect ( matlab . getReleaseInfo ( "R2022b" ) ) . resolves . toMatchObject ( release ) ;
103104 } ) ;
104105
106+ it ( "Sets minor version according to a or b release" , ( ) => {
107+ const R2022aRelease = {
108+ name : "r2022a" ,
109+ update : "" ,
110+ version : "2022.1.999" ,
111+ }
112+ expect ( matlab . getReleaseInfo ( "R2022a" ) ) . resolves . toMatchObject ( R2022aRelease ) ;
113+
114+ const R2022bRelease = {
115+ name : "r2022b" ,
116+ update : "" ,
117+ version : "2022.2.999" ,
118+ }
119+ expect ( matlab . getReleaseInfo ( "R2022b" ) ) . resolves . toMatchObject ( R2022bRelease ) ;
120+ } ) ;
121+
105122 it ( "allows specifying update number" , ( ) => {
106123 const releaseWithUpdate = {
107124 name : "r2022b" ,
108125 update : "u2" ,
109- version : "9.13.0 " ,
126+ version : "2022.2.2 " ,
110127 }
111128 expect ( matlab . getReleaseInfo ( "R2022bU2" ) ) . resolves . toMatchObject ( releaseWithUpdate ) ;
112129 } ) ;
113130
131+ it ( "displays message for invalid update level input format and uses latest" , ( ) => {
132+ expect ( matlab . getReleaseInfo ( "r2022bUpdate1" ) ) . rejects . toBeDefined ( ) ;
133+ } ) ;
134+
114135 it ( "rejects for unsupported release" , ( ) => {
115136 expect ( matlab . getReleaseInfo ( "R2022c" ) ) . rejects . toBeDefined ( ) ;
116137 } ) ;
117138
118139 it ( "rejects if for bad http response" , ( ) => {
119- jest . spyOn ( http . HttpClient . prototype , 'getJson ' ) . mockImplementation ( async ( ) => {
140+ jest . spyOn ( http . HttpClient . prototype , 'get ' ) . mockImplementation ( async ( ) => {
120141 return {
121- statusCode : 400 ,
122- result : undefined ,
123- headers : { }
142+ message : new httpjs . IncomingMessage ( new net . Socket ( ) ) ,
143+ readBody : ( ) => { return Promise . reject ( "Bam!" ) }
124144 } ;
125145 } )
126- expect ( matlab . getReleaseInfo ( "R2022b " ) ) . rejects . toBeDefined ( ) ;
146+ expect ( matlab . getReleaseInfo ( "latest " ) ) . rejects . toBeDefined ( ) ;
127147 } ) ;
128148 } ) ;
129149} ) ;
0 commit comments