Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions packages/stac_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.4.1"
version: "1.4.0"
checked_yaml:
dependency: transitive
description:
Expand Down Expand Up @@ -241,6 +241,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
flutter:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
frontend_server_client:
dependency: transitive
description:
Expand Down Expand Up @@ -353,6 +358,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.12.19"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.11.1"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -449,6 +462,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
source_gen:
dependency: transitive
description:
Expand Down Expand Up @@ -497,11 +515,12 @@ packages:
source: path
version: "1.5.0"
stac_logger:
dependency: "direct overridden"
dependency: transitive
description:
path: "../stac_logger"
relative: true
source: path
name: stac_logger
sha256: bc3c1cc486d59d2378c1e18bfd9bfa078be564b58d4ae2b3898633c05a02df26
url: "https://pub.dev"
source: hosted
version: "1.1.0"
stack_trace:
dependency: transitive
Expand Down Expand Up @@ -583,6 +602,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
url: "https://pub.dev"
source: hosted
version: "2.2.0"
vm_service:
dependency: transitive
description:
Expand Down Expand Up @@ -649,3 +676,4 @@ packages:
version: "3.1.3"
sdks:
dart: ">=3.10.0 <4.0.0"
flutter: ">=1.17.0"
53 changes: 53 additions & 0 deletions packages/stac_cli/test/commands/cli_commands_test.dart
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());
});
Comment thread
Pratikdate marked this conversation as resolved.

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);
});
});
}
70 changes: 70 additions & 0 deletions packages/stac_cli/test/utils/file_utils_test.dart
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);
}
}
});
});
}