-
-
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
6
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.
+98
−0
Open
Changes from all commits
Commits
Show all changes
6 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 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()); | ||
| }); | ||
|
|
||
| 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,49 @@ | ||
| 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', () { | ||
| final home = FileUtils.homeDirectory; | ||
| expect(home, isNotEmpty); | ||
| }); | ||
|
|
||
| test('configDirectory path is generated', () { | ||
| final config = FileUtils.configDirectory; | ||
| expect(config, isNotEmpty); | ||
| }); | ||
|
|
||
| // 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add tearDown to reset environment configuration.
The
setUpconfigures environment variables before each test, but there's no correspondingtearDownto clean up. This could cause state pollution if other test groups or subsequent test runs expect a clean environment.🧹 Proposed fix to add tearDown
📝 Committable suggestion
🤖 Prompt for AI Agents