-
-
Notifications
You must be signed in to change notification settings - Fork 104
feat(stac_cli): add unit testing infrastructure and core command tests #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pratikdate
wants to merge
12
commits into
StacDev:dev
Choose a base branch
from
Pratikdate:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8f8f208
feat(stac_cli): add unit testing infrastructure and core command tests
Pratikdate 4db325e
docs(test): add descriptive comments and improve reliability of CLI u…
Pratikdate 84f4abe
Merge branch 'StacDev:dev' into dev
Pratikdate cdda08c
style(stac_cli): fix formatting in test files
Pratikdate 6d422b8
Merge branch 'dev' of https://github.com/Pratikdate/stac into dev
Pratikdate f48feea
Merge branch 'dev' into dev
divyanshub024 0e2a6e1
test(cli): add environment teardown and validate home/config director…
Pratikdate 4d50d4f
Merge branch 'dev' into dev
Pratikdate 3897043
feat: add Dart/Flutter-native install path for Stac skills
Pratikdate 0df44b9
Revert "feat: add Dart/Flutter-native install path for Stac skills"
Pratikdate 03501b8
revert: temporary native-skills install changes from dev branch
Pratikdate 5a25b58
Merge branch 'dev' of https://github.com/Pratikdate/stac into dev
Pratikdate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,53 @@ | ||
| import 'package:test/test.dart'; | ||
| import 'package:args/command_runner.dart'; | ||
| import 'package:stac_cli/src/commands/build_command.dart'; | ||
| import 'package:stac_cli/src/commands/init_command.dart'; | ||
| import 'package:stac_cli/src/commands/deploy_command.dart'; | ||
| import 'package:stac_cli/src/config/env.dart'; | ||
|
|
||
| /// Test suite for verifying core Stac CLI commands. | ||
| void main() { | ||
| group('CLI Commands', () { | ||
| late CommandRunner<int> runner; | ||
|
|
||
| setUp(() { | ||
| // Initialize environment with mock values to satisfy required checks in services. | ||
| // This allows testing command configuration without needing real API keys. | ||
| configureEnvironment({ | ||
| 'STAC_BASE_API_URL': 'https://api.test.stac.dev', | ||
| 'STAC_GOOGLE_CLIENT_ID': 'test-client-id', | ||
| 'STAC_FIREBASE_API_KEY': 'test-api-key', | ||
| }); | ||
|
|
||
| runner = CommandRunner<int>('stac', 'Stac CLI test runner'); | ||
| runner.addCommand(BuildCommand()); | ||
| runner.addCommand(InitCommand()); | ||
| runner.addCommand(DeployCommand()); | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| configureEnvironment({}); | ||
| }); | ||
|
|
||
| test('build command has correct name and description', () { | ||
| final command = runner.commands['build']; | ||
| expect(command, isNotNull, reason: 'BuildCommand should be registered'); | ||
| expect(command!.name, equals('build')); | ||
| expect(command.description, isNotEmpty); | ||
| }); | ||
|
|
||
| test('init command has correct name and description', () { | ||
| final command = runner.commands['init']; | ||
| expect(command, isNotNull, reason: 'InitCommand should be registered'); | ||
| expect(command!.name, equals('init')); | ||
| expect(command.description, isNotEmpty); | ||
| }); | ||
|
|
||
| test('deploy command has correct name and description', () { | ||
| final command = runner.commands['deploy']; | ||
| expect(command, isNotNull, reason: 'DeployCommand should be registered'); | ||
| expect(command!.name, equals('deploy')); | ||
| expect(command.description, isNotEmpty); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or 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,70 @@ | ||
| import 'dart:io'; | ||
| import 'package:test/test.dart'; | ||
| import 'package:stac_cli/src/utils/file_utils.dart'; | ||
| import 'package:path/path.dart' as path; | ||
|
|
||
| /// Test suite for Stac CLI file utility operations. | ||
| void main() { | ||
| group('FileUtils', () { | ||
| // Basic verification of environment-dependent directory getters. | ||
| test('homeDirectory returns a non-empty string on this OS and points to an existing directory', () async { | ||
| final home = FileUtils.homeDirectory; | ||
| expect(home, isNotEmpty); | ||
| final dir = Directory(home); | ||
| expect(await dir.exists(), isTrue, reason: 'Home directory must exist'); | ||
| final stat = await dir.stat(); | ||
| expect(stat.type, equals(FileSystemEntityType.directory), reason: 'Home directory path must be a directory'); | ||
| }); | ||
|
|
||
| test('configDirectory path is generated and points to a valid directory', () async { | ||
| final config = FileUtils.configDirectory; | ||
| expect(config, isNotEmpty); | ||
|
|
||
| final dir = Directory(config); | ||
| final originallyExisted = await dir.exists(); | ||
|
|
||
| // Ensure config directory exists (creating it if necessary) | ||
| await FileUtils.ensureConfigDirectory(); | ||
|
|
||
| expect(await dir.exists(), isTrue, reason: 'Config directory must exist after ensuring'); | ||
| final stat = await dir.stat(); | ||
| expect(stat.type, equals(FileSystemEntityType.directory), reason: 'Config directory path must be a directory'); | ||
|
|
||
| // Clean up the created config directory if it didn't exist before the test | ||
| if (!originallyExisted && await dir.exists()) { | ||
| try { | ||
| await dir.delete(recursive: true); | ||
| } catch (_) {} | ||
| } | ||
| }); | ||
|
|
||
| // Integrated test for file system operations using a temporary directory. | ||
| test('integrated file operations: create, read, and delete', () async { | ||
| // Setup a clean temporary sandbox for this test. | ||
| final tempDir = Directory.systemTemp.createTempSync('stac_cli_test'); | ||
| final filePath = path.join(tempDir.path, 'test_file.txt'); | ||
|
|
||
| try { | ||
| // 1. Initial State: file should not exist. | ||
| expect(await FileUtils.fileExists(filePath), isFalse); | ||
|
|
||
| // 2. Write Operation: create file with content. | ||
| await FileUtils.writeFile(filePath, 'hello world'); | ||
| expect(await FileUtils.fileExists(filePath), isTrue); | ||
|
|
||
| // 3. Read Operation: verify content matches. | ||
| final content = await FileUtils.readFile(filePath); | ||
| expect(content, equals('hello world')); | ||
|
|
||
| // 4. Delete Operation: cleanup file. | ||
| await FileUtils.deleteFile(filePath); | ||
| expect(await FileUtils.fileExists(filePath), isFalse); | ||
| } finally { | ||
| // Always cleanup the temporary directory logic even if tests fail. | ||
| if (tempDir.existsSync()) { | ||
| tempDir.deleteSync(recursive: true); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.