This commit is contained in:
Matthew Hughes 2025-06-20 18:54:05 -04:00 committed by GitHub
commit 69077f10cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 118 additions and 9 deletions

View file

@ -285,7 +285,7 @@ describe('setup-go', () => {
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
});
it('does not export any variables for Go versions >=1.9', async () => {
it('does not export GOROOT for Go versions >=1.9', async () => {
inputs['go-version'] = '1.13.0';
inSpy.mockImplementation(name => inputs[name]);
@ -298,7 +298,7 @@ describe('setup-go', () => {
});
await main.run();
expect(vars).toStrictEqual({});
expect(vars).not.toHaveProperty('GOROOT');
});
it('exports GOROOT for Go versions <1.9', async () => {
@ -314,9 +314,7 @@ describe('setup-go', () => {
});
await main.run();
expect(vars).toStrictEqual({
GOROOT: toolPath
});
expect(vars).toHaveProperty('GOROOT', toolPath);
});
it('finds a version of go already in the cache', async () => {
@ -989,4 +987,68 @@ use .
}
);
});
describe('go-version-file-toolchain', () => {
const goModContents = `module example.com/mymodule
go 1.14
toolchain go1.21.0
require (
example.com/othermodule v1.2.3
example.com/thismodule v1.2.3
example.com/thatmodule v1.2.3
)
replace example.com/thatmodule => ../thatmodule
exclude example.com/thismodule v1.3.0
`;
const goWorkContents = `go 1.19
toolchain go1.21.0
use .
`;
it('reads version from toolchain directive in go.mod', async () => {
inputs['go-version-file'] = 'go.mod';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.21.0');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.21.0...');
expect(logSpy).toHaveBeenCalledWith('matching 1.21.0...');
});
it('reads version from toolchain directive in go.work', async () => {
inputs['go-version-file'] = 'go.work';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(goWorkContents));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.21.0');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.21.0...');
expect(logSpy).toHaveBeenCalledWith('matching 1.21.0...');
});
});
it('exports GOTOOLCHAIN and sets it in current process env', async () => {
inputs['go-version'] = '1.21.0';
inSpy.mockImplementation(name => inputs[name]);
const vars: {[key: string]: string} = {};
exportVarSpy.mockImplementation((name: string, val: string) => {
vars[name] = val;
});
await main.run();
expect(vars).toStrictEqual({GOTOOLCHAIN: 'local'});
expect(process.env).toHaveProperty('GOTOOLCHAIN', 'local');
});
});