From 8f8f208319691376db7498a1d1a63aa94c3b4913 Mon Sep 17 00:00:00 2001 From: chcweblogin Date: Fri, 3 Apr 2026 17:19:23 +0530 Subject: [PATCH 1/3] feat(stac_cli): add unit testing infrastructure and core command tests --- .../test/commands/cli_commands_test.dart | 45 +++++++++++++++++++ .../stac_cli/test/utils/file_utils_test.dart | 40 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 packages/stac_cli/test/commands/cli_commands_test.dart create mode 100644 packages/stac_cli/test/utils/file_utils_test.dart 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..a0955db2 --- /dev/null +++ b/packages/stac_cli/test/commands/cli_commands_test.dart @@ -0,0 +1,45 @@ +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'; + +void main() { + group('CLI Commands', () { + late CommandRunner runner; + + setUp(() { + 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); + 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); + 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); + 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..d93e6672 --- /dev/null +++ b/packages/stac_cli/test/utils/file_utils_test.dart @@ -0,0 +1,40 @@ +import 'dart:io'; +import 'package:test/test.dart'; +import 'package:stac_cli/src/utils/file_utils.dart'; +import 'package:path/path.dart' as path; + +void main() { + group('FileUtils', () { + test('homeDirectory returns a string', () { + final home = FileUtils.homeDirectory; + expect(home, isNotEmpty); + }); + + test('configDirectory is a valid path', () { + final config = FileUtils.configDirectory; + expect(config, isNotEmpty); + }); + + test('file operations', () async { + final tempDir = Directory.systemTemp.createTempSync('stac_cli_test'); + final filePath = path.join(tempDir.path, 'test_file.txt'); + + // Test fileExists + expect(await FileUtils.fileExists(filePath), isFalse); + + // Test writeFile and fileExists + await FileUtils.writeFile(filePath, 'hello world'); + expect(await FileUtils.fileExists(filePath), isTrue); + + // Test readFile + final content = await FileUtils.readFile(filePath); + expect(content, 'hello world'); + + // Test deleteFile + await FileUtils.deleteFile(filePath); + expect(await FileUtils.fileExists(filePath), isFalse); + + tempDir.deleteSync(recursive: true); + }); + }); +} From 4db325e6609c34210ba42c702ce22f01ca474341 Mon Sep 17 00:00:00 2001 From: chcweblogin Date: Fri, 3 Apr 2026 17:22:13 +0530 Subject: [PATCH 2/3] docs(test): add descriptive comments and improve reliability of CLI unit tests --- .../test/commands/cli_commands_test.dart | 10 +++-- .../stac_cli/test/utils/file_utils_test.dart | 41 +++++++++++-------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/packages/stac_cli/test/commands/cli_commands_test.dart b/packages/stac_cli/test/commands/cli_commands_test.dart index a0955db2..97700cf6 100644 --- a/packages/stac_cli/test/commands/cli_commands_test.dart +++ b/packages/stac_cli/test/commands/cli_commands_test.dart @@ -5,16 +5,20 @@ 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()); @@ -23,21 +27,21 @@ void main() { test('build command has correct name and description', () { final command = runner.commands['build']; - expect(command, isNotNull); + 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); + 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); + 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 index d93e6672..50bc1e28 100644 --- a/packages/stac_cli/test/utils/file_utils_test.dart +++ b/packages/stac_cli/test/utils/file_utils_test.dart @@ -3,38 +3,47 @@ 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', () { - test('homeDirectory returns a string', () { + // 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 is a valid path', () { + test('configDirectory path is generated', () { final config = FileUtils.configDirectory; expect(config, isNotEmpty); }); - test('file operations', () async { + // 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'); - // Test fileExists - expect(await FileUtils.fileExists(filePath), isFalse); + try { + // 1. Initial State: file should not exist. + expect(await FileUtils.fileExists(filePath), isFalse); - // Test writeFile and fileExists - await FileUtils.writeFile(filePath, 'hello world'); - expect(await FileUtils.fileExists(filePath), isTrue); + // 2. Write Operation: create file with content. + await FileUtils.writeFile(filePath, 'hello world'); + expect(await FileUtils.fileExists(filePath), isTrue); - // Test readFile - final content = await FileUtils.readFile(filePath); - expect(content, 'hello world'); + // 3. Read Operation: verify content matches. + final content = await FileUtils.readFile(filePath); + expect(content, equals('hello world')); - // Test deleteFile - await FileUtils.deleteFile(filePath); - expect(await FileUtils.fileExists(filePath), isFalse); - - tempDir.deleteSync(recursive: true); + // 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); + } + } }); }); } From cdda08c7792ec145747beda68986dde80618d889 Mon Sep 17 00:00:00 2001 From: chcweblogin Date: Sun, 5 Apr 2026 12:44:13 +0530 Subject: [PATCH 3/3] style(stac_cli): fix formatting in test files --- packages/stac_cli/test/commands/cli_commands_test.dart | 2 +- packages/stac_cli/test/utils/file_utils_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stac_cli/test/commands/cli_commands_test.dart b/packages/stac_cli/test/commands/cli_commands_test.dart index 97700cf6..f8c9246b 100644 --- a/packages/stac_cli/test/commands/cli_commands_test.dart +++ b/packages/stac_cli/test/commands/cli_commands_test.dart @@ -18,7 +18,7 @@ void main() { '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()); diff --git a/packages/stac_cli/test/utils/file_utils_test.dart b/packages/stac_cli/test/utils/file_utils_test.dart index 50bc1e28..76c0cdd1 100644 --- a/packages/stac_cli/test/utils/file_utils_test.dart +++ b/packages/stac_cli/test/utils/file_utils_test.dart @@ -22,7 +22,7 @@ void main() { // 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);