Skip to content

Commit

Permalink
support for mac and linux
Browse files Browse the repository at this point in the history
  • Loading branch information
laurennat committed Jun 17, 2024
1 parent 685e412 commit c37fd0a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 68 deletions.
51 changes: 0 additions & 51 deletions extensions/integration-tests/dockerInstall.ps1

This file was deleted.

34 changes: 34 additions & 0 deletions extensions/integration-tests/dockerUnix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

echo "Waiting for Docker Desktop to start..."

# Open Docker Desktop, check the operating system
if [ "$(uname)" == "Darwin" ]; then
open -a Docker
elif [ "$(uname)" == "Linux" ]; then
systemctl --user start docker-desktop
else
echo "Unsupported operating system: $(uname)"
exit 1
fi

echo "Starting Docker Desktop..."
sleep 60


echo "Starting SQL Servers..."

# Stop and remove existing containers
docker stop sql2017integrationtestdb
docker rm sql2017integrationtestdb
docker stop sql2019integrationtestdb
docker rm sql2019integrationtestdb
docker stop azuresqlintegrationtestdb
docker rm azuresqlintegrationtestdb

# Run new SQL Server containers
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$sql2017pass" -p 1434:1433 --name sql2017integrationtestdb -d mcr.microsoft.com/mssql/server:2017-latest
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$sql2019pass" -p 1435:1433 --name sql2019integrationtestdb -d mcr.microsoft.com/mssql/server:2019-latest
docker run --cap-add SYS_PTRACE -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=$azuresqlpass" -p 1436:1433 --name azuresqlintegrationtestdb -d mcr.microsoft.com/azure-sql-edge

echo "Done!"
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Get where docker is installed
$dockerDirectory = (Get-Command docker).Source
$dockerDirectory = $dockerDirectory.Substring(0, $dockerDirectory.Length - 21)
echo $dockerDirectory
$dockerDirectory = $dockerDirectory.Substring(0, $dockerDirectory.Length - 15)
echo $dockerDirectory

Write-Output "Waiting for Docker Desktop to start..."
Start-Process -FilePath "$dockerDirectory\Docker Desktop.exe"
Expand Down
2 changes: 1 addition & 1 deletion extensions/integration-tests/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ When these tests are ran, Azure Data Studio will be launched using new temp fold
The integration test suite has been added to ADS windows pipeline to run the test and report the results, you can find the test results under the test tab.

2. Local environment:
1. Install and start [Docker Desktop](https://docs.docker.com/desktop/) for your system
1. Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
1. Close all currently active VS Code windows
1. Open a terminal window/command line window
1. Run `az login` to login with your Microsoft AAD account.
1. Navigate to this folder and then run `node setEnvironmentVariables.js`, there are different options, by default VS Code will be opened.
1. Terminal(Mac)/CMD(Windows): `node setEnvironmentVariables.js Terminal`
2. Git-Bash on Windows: `node setEnvironmentVariables.js BashWin`
3. This command will install docker if you don't have it, and then run the docker containers required for tests. If it goes through the install docker process, it may prompt you during installation. Just hit continue.
1. A new window will be opened based on your selection and the new window will have the required environment variables set.
2. In the new window navigate to the scripts folder and run sql-test-integration.[bat|sh]

Expand Down
26 changes: 11 additions & 15 deletions extensions/integration-tests/setEnvironmentVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (!LAUNCH_OPTION) {
// How to install it:
// Open ADS and run command 'Configure Python for Notebooks' command and install it to the default folder,
// if you install it to a different folder you will have to update the value of this variable
const NOTEBOOK_PYTHON_INSTALL_PATH = path.join(os.homedir(), 'azuredatastudio-python');
const NOTEBOOK_PYTHON_INSTALL_PATH = "C:\\Users\\laurennathan\\AppData\\Local\\Programs\\Python\\Python311" //path.join(os.homedir(), 'azuredatastudio-python');

/**
* ----------------------------------------------------------------------------------------------
Expand All @@ -82,17 +82,11 @@ if (!fs.existsSync(NOTEBOOK_PYTHON_INSTALL_PATH)) {

// Database password generation
function generatePassword() {
const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numberChars = '0123456789';

let password = '';

password += lowercaseChars.charAt(Math.floor(Math.random() * lowercaseChars.length));
password += uppercaseChars.charAt(Math.floor(Math.random() * uppercaseChars.length));
password += numberChars.charAt(Math.floor(Math.random() * numberChars.length));
password += Math.random().toString(36).slice(-7);

const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let password = "";
for (let n = 0; n < 128; n++) {
password += chars.charAt(Math.random() * chars.length)
}
return password;
}

Expand All @@ -110,10 +104,12 @@ process.env[ENVAR_SQL_2017_PASS] = generatePassword();
process.env[ENVAR_SQL_2019_PASS] = generatePassword();
process.env[ENVAR_AZURE_SQL_PASS] = generatePassword();

// run the docker.ps1 powershell script, and wait for it to finish
// show all output from the command
const command = `powershell.exe -Command "Start-Process powershell.exe -ArgumentList '-Command', '$sql2017pass=''${process.env[ENVAR_SQL_2017_PASS]}'';$sql2019pass=''${process.env[ENVAR_SQL_2019_PASS]}'';$azuresqlpass=''${process.env[ENVAR_AZURE_SQL_PASS]}'';\\"${__dirname}\\dockerInstall.ps1\\"' -Verb RunAs"`;
// Start docker containers
const wincommand = `powershell.exe -Command "Start-Process powershell.exe -ArgumentList '-Command', '$sql2017pass=''${process.env[ENVAR_SQL_2017_PASS]}'';$sql2019pass=''${process.env[ENVAR_SQL_2019_PASS]}'';$azuresqlpass=''${process.env[ENVAR_AZURE_SQL_PASS]}'';\\"${__dirname}\\dockerWindows.ps1\\"' -Verb RunAs"`;
const unixcommand = `bash -c '$sql2017pass=${process.env[ENVAR_SQL_2017_PASS]} $sql2019pass=${process.env[ENVAR_SQL_2019_PASS]} $azuresqlpass=${process.env[ENVAR_AZURE_SQL_PASS]} ${__dirname}/dockerUnix.sh'`;

// Determine the OS and set the appropriate command
const command = os.platform() === 'win32' ? wincommand : unixcommand;
// wait for exec and it's child processes to finish
exec(command, (error, stderr) => {
if (error) {
Expand Down

0 comments on commit c37fd0a

Please sign in to comment.