diff --git a/packages/stac_cli/test/commands/cli_commands_test.dart b/packages/stac_cli/test/commands/cli_commands_test.dart new file mode 100644 index 00000000..f8c9246b --- /dev/null +++ b/packages/stac_cli/test/commands/cli_commands_test.dart @@ -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 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('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); + }); + }); +} diff --git a/packages/stac_cli/test/utils/file_utils_test.dart b/packages/stac_cli/test/utils/file_utils_test.dart new file mode 100644 index 00000000..76c0cdd1 --- /dev/null +++ b/packages/stac_cli/test/utils/file_utils_test.dart @@ -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); + } + } + }); + }); +}