Skip to content

Commit 9fa17af

Browse files
author
Colin Wahl
authored
Add tests for the majority of the bindings in the library (#9)
* add tests for GitHub.Actions.Core bindings * fix GitHub.Actions.Core.debug implementation * add tests for GitHub.Actions.Cache * improve Core.group test * add tests for GitHub.Actions.Exec * Add tests for GitHub.Actions.IO * add tests for GitHub.Actions.ToolCache bindings * ls ~> pwd for less noisy logs
1 parent 35ca19e commit 9fa17af

File tree

4 files changed

+111
-3
lines changed

4 files changed

+111
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ jobs:
4848

4949
- name: Run tests
5050
uses: ./test
51+
with:
52+
testinput: test

src/GitHub/Actions/Core.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ foreign import isDebugImpl :: Effect Boolean
111111
isDebug :: Effect Boolean
112112
isDebug = isDebugImpl
113113

114-
foreign import debugImpl :: String -> Effect Unit
114+
foreign import debugImpl :: EffectFn1 String Unit
115115

116116
-- | Writes debug message to user log
117117
debug :: String -> Effect Unit
118-
debug = debugImpl
118+
debug = runEffectFn1 debugImpl
119119

120120
foreign import errorImpl :: EffectFn1 String Unit
121121

test/Main.purs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,115 @@ import Control.Monad.Except.Trans (runExceptT)
66
import Data.Either (Either(..))
77
import Data.Maybe (Maybe(..))
88
import Effect (Effect)
9+
import Effect.Aff (launchAff_, runAff_)
10+
import Effect.Class (liftEffect)
911
import Effect.Exception (message)
12+
import GitHub.Actions.Cache as Cache
1013
import GitHub.Actions.Core as Core
14+
import GitHub.Actions.Exec as Exec
15+
import GitHub.Actions.IO as IO
1116
import GitHub.Actions.ToolCache as ToolCache
1217

1318
main :: Effect Unit
1419
main = do
1520
Core.info "Starting test action..."
21+
22+
-- Tests for GitHub.Actions.Core
23+
Core.exportVariable { key: "testkey", value: "test" }
24+
Core.setOutput { name: "testoutput", value: "test" }
25+
Core.setSecret "testoutput"
26+
Core.addPath "/test/path"
27+
resultCore <- runExceptT do
28+
_ <- Core.getInput' "testinput"
29+
_ <- Core.getInput { name: "testinput", options: Nothing }
30+
Core.getInput { name: "testinput", options: Just { required: true } }
31+
case resultCore of
32+
Left err -> Core.setFailed (message err)
33+
Right _ -> Core.info "No errors in GitHub.Actions.Core ExceptT functions"
34+
Core.setCommandEcho false
35+
_ <- Core.isDebug
36+
Core.debug "Testing debug"
37+
Core.error "Testing error"
38+
Core.warning "Testing warning"
39+
Core.info "Testing info"
40+
Core.startGroup "testgroup"
41+
Core.endGroup
42+
Core.saveState { name: "teststate", value: "test" }
43+
_ <- Core.getState "teststate"
44+
launchAff_ $ Core.group
45+
{ name: "testGroup"
46+
, fn: liftEffect (Core.info "In testGroup")
47+
}
48+
49+
-- Tests for GitHub.Actions.Cache
50+
let
51+
cacheCb = case _ of
52+
Left err -> Core.setFailed (message err)
53+
Right _ -> Core.info "No errors in restoreCache"
54+
runAff_ cacheCb $ runExceptT do
55+
_ <- Cache.saveCache' { paths: [], key: "restorecache" }
56+
_ <- Cache.saveCache { paths: [], key: "restorecache", options: Nothing }
57+
_ <- Cache.saveCache { paths: [], key: "restorecache", options: Just (Cache.defaultUploadOptions { uploadConcurrency = Just 10.0 }) }
58+
_ <- Cache.restoreCache' { paths: [], primaryKey: "restorecache" }
59+
_ <- Cache.restoreCache { paths: [], primaryKey: "restorecache", restoreKeys: Nothing, options: Nothing }
60+
_ <- Cache.restoreCache { paths: [], primaryKey: "restorecache", restoreKeys: Just [ "a" ], options: Nothing }
61+
Cache.restoreCache { paths: [], primaryKey: "restorecaceh", restoreKeys: Just [ "a" ], options: Just (Cache.defaultDownloadOptions { useAzureSdk = Just true, downloadConcurrency = Just true, timeoutInMs = Just 10.0 })}
62+
63+
-- Tests for GitHub.Actions.Exec
64+
let
65+
execCb = case _ of
66+
Left err -> Core.setFailed (message err)
67+
Right _ -> Core.info "No errors in exec"
68+
runAff_ execCb $ runExceptT do
69+
_ <- Exec.exec' "pwd"
70+
_ <- Exec.exec { command: "pwd", args: Just [ "-L" ], options: Nothing }
71+
Exec.exec { command: "pwd", args: Just [ "-L" ], options: Just (Exec.defaultExecOptions { delay = Just 10.0 })}
72+
73+
-- Tests for GitHub.Actions.IO
74+
let
75+
ioCb = case _ of
76+
Left err -> Core.setFailed (message err)
77+
Right _ -> Core.info "No errors in io"
78+
runAff_ ioCb $ runExceptT do
79+
_ <- Exec.exec' "touch test.txt"
80+
_ <- IO.cp' { source: "test.txt", dest: "test1.txt" }
81+
_ <- IO.cp { source: "test1.txt", dest: "test2.txt", options: Just (IO.defaultCopyOptions { force = Just true })}
82+
_ <- IO.mv' { source: "test2.txt", dest: "test3.txt" }
83+
_ <- IO.mv { source: "test3.txt", dest: "test4.txt", options: Just (IO.defaultMoveOptions { force = Just true }) }
84+
_ <- IO.rmRF { inputPath: "test4.txt" }
85+
_ <- IO.mkdirP { fsPath: "testDir" }
86+
_ <- IO.which' "purs"
87+
IO.which { tool: "purs", check: Just true }
88+
89+
-- Tests for GitHub.Actions.ToolCache
90+
let
91+
toolCacheCb = case _ of
92+
Left err -> Core.setFailed (message err)
93+
Right _ -> Core.info "No errors in ToolCache"
94+
runAff_ toolCacheCb $ runExceptT do
95+
pursPath <- ToolCache.downloadTool' "https://github.com/purescript/purescript/releases/download/v0.13.8/linux64.tar.gz"
96+
_ <- ToolCache.downloadTool { url: "https://github.com/purescript/purescript/releases/download/v0.13.8/linux64.tar.gz", dest: Just "~/purspath", auth: Nothing }
97+
_ <- ToolCache.downloadTool { url: "https://github.com/purescript/purescript/releases/download/v0.13.8/linux64.tar.gz", dest: Just "~/purspath", auth: Just "blahhh" }
98+
extractedPurs <- ToolCache.extractTar' pursPath
99+
_ <- ToolCache.extractTar { file: pursPath, dest: Just "/extractedpurs", flags: Nothing }
100+
_ <- ToolCache.extractTar { file: pursPath, dest: Just "/extractedpurs", flags: Just [] }
101+
zipPath <- ToolCache.downloadTool' "https://github.com/purescript/purescript/archive/v0.13.8.zip"
102+
_ <- ToolCache.extractZip' zipPath
103+
_ <- ToolCache.extractZip { file: zipPath, dest: Just "/extractedpurszip" }
104+
_ <- ToolCache.cacheDir' { sourceDir: extractedPurs, tool: "purs", version: "v0.13.8" }
105+
_ <- ToolCache.cacheDir { sourceDir: extractedPurs, tool: "purs", version: "v0.13.8", arch: Just "arm" }
106+
_ <- ToolCache.cacheFile' { sourceFile: pursPath, targetFile: "testtarget", tool: "purs", version: "v0.13.8" }
107+
_ <- ToolCache.cacheFile { sourceFile: pursPath, targetFile: "testtarget", tool: "purs", version: "v0.13.8", arch: Just "arm" }
108+
pursManifest <- ToolCache.getManifestFromRepo' { owner: "purescript", repo: "purescript" }
109+
_ <- ToolCache.getManifestFromRepo { owner: "purescript", repo: "purescript", auth: Just "blah", branch: Just "master" }
110+
_ <- ToolCache.findFromManifest { versionSpec: "v0.13.8", stable: true, manifest: pursManifest, archFilter: Nothing }
111+
ToolCache.findFromManifest { versionSpec: "v0.13.8", stable: true, manifest: pursManifest, archFilter: Just "arm" }
112+
16113
result <- runExceptT do
17114
_ <- ToolCache.find' { toolName: "my-tool", versionSpec: "12.x" }
18-
ToolCache.find { toolName: "my-tool", versionSpec: "12.x", arch: Just "armv6" }
115+
_ <- ToolCache.find { toolName: "my-tool", versionSpec: "12.x", arch: Just "armv6" }
116+
_ <- ToolCache.findAllVersions' "purs"
117+
ToolCache.findAllVersions { toolName: "purs", arch: Just "arm" }
19118
case result of
20119
Left err -> Core.setFailed (message err)
21120
Right _ -> Core.info "No errors in find"

test/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ description: 'Test out bindings in this library'
33
runs:
44
using: 'node12'
55
main: '../dist/index.js'
6+
inputs:
7+
testinput:
8+
description: 'Test input for test action'
9+
required: true
10+
outputs:
11+
testoutput:
12+
description: 'Test output for test action'

0 commit comments

Comments
 (0)