Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Jul 18, 2023
1 parent 8998c68 commit 42a70ec
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
90 changes: 61 additions & 29 deletions .github/workflows/windows-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,48 @@ on:
- '**.md'

jobs:
create-link-on-windows:
create-link-if-not-default:
runs-on: windows-latest
name: 'Setup ${{ matrix.go }}, cache: ${{ matrix.cache }}'
strategy:
matrix:
cache: [false, true]
go: [1.20.1, 1.20.5]
name: 'Setup ${{ matrix.go }} cache: ${{ matrix.cache }}'
go: [1.20.1]
steps:
- uses: actions/checkout@v3

- uses: ./
- name: non-default-cache-${{ matrix.cache }}-${{ matrix.go }}
uses: ./
with:
go-version: ${{ matrix.go }}
cache: ${{ matrix.cache }}
name: v4-cache-${{ matrix.cache }}

- run: |
if [ -e 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64' ];then
echo 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64 should not exist for hosted version of go';
exit 1
fi

- name: 'Drive C: should have zero size link'
run: |
du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'
# make sure drive c: contains the folder
# make sure drive c: contains only a link
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t')
if [ $size -eq 0 ];then
echo 'Size of the hosted go installed on drive c: must be above zero'
if [ $size -ne 0 ];then
echo 'Size of the link created on drive c: must be 0'
exit 1
fi
shell: bash
name: Hosted go should not have link
if: ${{ matrix.go == '1.20.5' }}

- run: |
# Drive D: is small, take care the action does not eat up the space
- name: 'Drive D: space usage should be below 1G'
run: |
du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'
size=$(du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t')
# make sure archive does not take lot of space
if [ $size -gt 999 ];then
echo 'Size of installed on drive d: go is too big';
exit 1
fi
du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'
# make sure drive c: contains only a link
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t')
if [ $size -ne 0 ];then
echo 'Size of the link created on drive c: must be 0'
exit 1
fi
shell: bash
name: Disk usage
if: ${{ matrix.go != '1.20.5' }}

- run: |
# make sure the Go installation has not been changed to the end user
- name: Test paths and environments
run: |
echo $PATH
which go
go version
Expand All @@ -78,4 +66,48 @@ jobs:
exit 1
fi
shell: bash
name: test paths and environments

find-default-go:
name: 'Find default go version'
runs-on: windows-latest
outputs:
version: ${{ steps.goversion.outputs.version }}
steps:
- run: |
version=`go env GOVERSION|sed s/^go//`
echo "default go version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
id: goversion
shell: bash
dont-create-link-if-default:
name: 'Use default go, cache: ${{ matrix.cache }}'
runs-on: windows-latest
needs: find-default-go
strategy:
matrix:
cache: [false, true]
steps:
- uses: actions/checkout@v3

- uses: ./
with:
go-version: ${{ needs.find-default-go.outputs.version }}
cache: ${{ matrix.cache }}

- name: 'Drive C: should have Go installation'
run: |
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64'|cut -f1 -d$'\t')
if [ $size -eq 0 ];then
echo 'Size of the hosted go installed on drive c: must be above zero'
exit 1
fi
shell: bash

- name: 'Drive D: should not have Go installation'
run: |
if [ -e 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64' ];then
echo 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64 should not exist for hosted version of go';
exit 1
fi
shell: bash
3 changes: 2 additions & 1 deletion __tests__/setup-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import * as im from '../src/installer';
import goJsonData from './data/golang-dl.json';
import matchers from '../matchers.json';
import goTestManifest from './data/versions-manifest.json';
import {addExecutablesToCache, IGoVersionInfo} from '../src/installer';
const matcherPattern = matchers.problemMatcher[0].pattern[0];
const matcherRegExp = new RegExp(matcherPattern.regexp);
const win32Join = path.win32.join;
const posixJoin = path.posix.join;

jest.setTimeout(10000);

describe('setup-go', () => {
let inputs = {} as any;
let os = {} as any;
Expand Down
3 changes: 3 additions & 0 deletions __tests__/windows-performance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ describe('Windows performance workaround', () => {
jest.clearAllMocks();
process.env['RUNNER_TOOL_CACHE'] = runnerToolCache;
});
// addExecutablesToCache uses 3rd party dependency toolkit.cache under the hood
// that currently is implemented with RUNNER_TOOL_CACHE environment variable
// Make sure the implementation has not been changed
it('addExecutablesToCache should depend on env[RUNNER_TOOL_CACHE]', async () => {
const info: IGoVersionInfo = {
type: 'dist',
Expand Down

0 comments on commit 42a70ec

Please sign in to comment.