1+ import { assert , expect } from "chai" ;
2+ import { HelperArtifactDownload } from "../helper-artifact-download"
3+ import * as path from 'path' ;
4+ import * as os from 'os' ;
5+ import * as uuid from 'uuid' ;
6+ import * as fs from 'fs'
7+ import { HelperInputOutput } from "../helper-input-output" ;
8+
9+ describe ( "Artifact path resolving tests" , ( ) => {
10+ before ( ( ) => { process . env . GITHUB_WORKSPACE = __dirname ; } ) ;
11+ after ( ( ) => { process . env . GITHUB_WORKSPACE = undefined ; } ) ;
12+
13+ [ "." , ".." , "fake" , "fake/path" ] . forEach ( relativePathBase => {
14+ it ( "Should resolve relative paths to absolute paths" , ( ) => {
15+ const sut = new HelperArtifactDownload ( new HelperInputOutput ( ) ) ;
16+ const dirName = uuid . v4 ( ) ;
17+ const relativePath = path . join ( relativePathBase , dirName ) ;
18+ const expectedAbsolutePath = path . join ( __dirname , relativePath ) ;
19+
20+ let actualResolvedPath : fs . PathLike = "" ;
21+ try {
22+ // ACT
23+ actualResolvedPath = sut . resolveOrCreateDirectory ( relativePath ) ;
24+
25+ // ASSERT
26+ assert . equal ( actualResolvedPath , expectedAbsolutePath ) ;
27+ }
28+ finally {
29+ fs . rmSync ( actualResolvedPath , { force : true , recursive : true } )
30+ }
31+ } )
32+ } )
33+
34+ it ( "Should detect and recognize absolute paths" , ( ) => {
35+ const sut = new HelperArtifactDownload ( new HelperInputOutput ( ) ) ;
36+ const dirName = uuid . v4 ( ) ;
37+ const expectedAbsolutePath = path . join ( __dirname , dirName ) ;
38+
39+ let actualResolvedPath : fs . PathLike = "" ;
40+ try {
41+ // ACT
42+ actualResolvedPath = sut . resolveOrCreateDirectory ( expectedAbsolutePath ) ;
43+
44+ // ASSERT
45+ assert . equal ( actualResolvedPath , expectedAbsolutePath ) ;
46+ }
47+ finally {
48+ fs . rmSync ( actualResolvedPath , { force : true , recursive : true } )
49+ }
50+ } )
51+ } )
0 commit comments