-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regular execution integration tests (#618)
- Loading branch information
Showing
4 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_bundle") | ||
load("//:helper.bzl", "santa_unit_test") | ||
|
||
santa_unit_test( | ||
name = "SNTExecTest", | ||
data = [ | ||
"//Source/santad/testdata:binaryrules_testdata", | ||
], | ||
srcs = [ | ||
"SNTExecTest.m" | ||
], | ||
deps = [], | ||
minimum_os_version = "10.15", | ||
) | ||
|
||
test_suite( | ||
name = "integration_tests", | ||
tests = [ | ||
":SNTExecTest", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// Copyright 2021 Google Inc. All rights reserved. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
#import <Foundation/Foundation.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#include <unistd.h> | ||
|
||
@interface SNTExecTest : XCTestCase | ||
@end | ||
|
||
@implementation SNTExecTest : XCTestCase | ||
- (void)setUp { | ||
[super setUp]; | ||
fclose(stdout); | ||
} | ||
|
||
- (void)checkExecution:(NSString *)path shouldExec:(BOOL)shouldExec { | ||
__block int status; | ||
|
||
XCTestExpectation *expectation = | ||
[self expectationWithDescription:@"Wait for test binary to execute"]; | ||
|
||
__block NSTask *task = [[NSTask alloc] init]; | ||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ | ||
task.launchPath = path; | ||
[task launch]; | ||
[task waitUntilExit]; | ||
status = [task terminationStatus]; | ||
[expectation fulfill]; | ||
}); | ||
|
||
[self waitForExpectationsWithTimeout:20.0 | ||
handler:^(NSError *error) { | ||
XCTAssertFalse([task isRunning], @"Test timed out: %@", error); | ||
[task terminate]; | ||
}]; | ||
|
||
BOOL didExec = (status == 0); | ||
XCTAssertEqual(didExec, shouldExec); | ||
} | ||
|
||
- (void)testShouldExecute { | ||
NSString *testPath = @"santa/Source/santad/testdata/binaryrules"; | ||
NSString *fullTestPath = [NSString pathWithComponents:@[ | ||
[[[NSProcessInfo processInfo] environment] objectForKey:@"TEST_SRCDIR"], testPath | ||
]]; | ||
NSDictionary *testCases = @{ | ||
@"goodbinary" : @YES, | ||
@"badbinary" : @NO, | ||
@"noop" : @YES, | ||
}; | ||
for (NSString *binary in testCases) { | ||
[self checkExecution:[NSString pathWithComponents:@[ fullTestPath, binary ]] | ||
shouldExec:[testCases[binary] boolValue]]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
|
||
run_tests() { | ||
local -a TEST_FLAGS=( --strategy=TestRunner=standalone --test_output=all ) | ||
cd ./integration | ||
time bazel test "${TEST_FLAGS[@]}" -- ... | ||
} | ||
|
||
setup() { | ||
./start_env.sh | ||
sudo santactl sync --debug | ||
} | ||
|
||
main() { | ||
setup | ||
run_tests | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters