Skip to content

Commit

Permalink
Change tests to automatically download collector if not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpo committed Sep 15, 2023
1 parent c573ada commit 27953ad
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/commonSetupOnce.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function commonSetupOnce(testCase)
testCase.PidFile = "testoutput.txt";

% process definitions
testCase.OtelcolName = "otelcol";
if ispc
testCase.ListPid = @(name)"tasklist /fi ""IMAGENAME eq " + name + ".exe""";
testCase.ReadPidList = @(file)readtable(file, "VariableNamingRule", "preserve", "NumHeaderLines", 3, "MultipleDelimsAsOne", true, "Delimiter", " ");
Expand Down Expand Up @@ -55,13 +54,16 @@ function commonSetupOnce(testCase)
testCase.Sigint = @(id)"kill -s INT " + id;
testCase.Sigterm = @(id)"kill -s TERM " + id;
if computer == "MACA64"
% only the contrib version of OpenTelemetry Collector is available on Apple silicon
testCase.OtelcolName = "otelcol-contrib";
otelcol_arch_name = "darwin_arm64";
else
otelcol_arch_name = "darwin_amd64";
end
otelcol_exe_ext = "";

end

% OpenTelemetry Collector
otelcolname = "otelcol";
if isempty(otelcolroot)
% collector not pre-installed
otelcol_version = "0.85.0";
Expand All @@ -71,13 +73,21 @@ function commonSetupOnce(testCase)
otelcolroot = fullfile(tempdir, otelcol_zipfilename);

% look for it in tempdir, download and install if it doesn't exist
if ~exist(fullfile(otelcolroot, testCase.OtelcolName + otelcol_exe_ext),"file")
if ~(exist(fullfile(otelcolroot, otelcolname + otelcol_exe_ext),"file") || ...
exist(fullfile(otelcolroot,otelcolname + "-contrib" + otelcol_exe_ext),"file"))
% download and install
otelcol_tar = gunzip(fullfile(otelcol_url, otelcol_zipfilename + ".tar.gz"), otelcolroot);
otelcol_tar = otelcol_tar{1}; % should have only extracted 1 tar file
untar(otelcol_tar, otelcolroot);
delete(otelcol_tar);
end
end
% check for contrib version
if exist(fullfile(otelcolroot,otelcolname + "-contrib" + otelcol_exe_ext),"file")
testCase.OtelcolName = otelcolname + "-contrib";
else
testCase.OtelcolName = otelcolname;
end

testCase.Otelcol = fullfile(otelcolroot, testCase.OtelcolName);

Expand Down

1 comment on commit 27953ad

@duncanpo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.