Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Mar 14, 2024
1 parent 176e00f commit 0537065
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/commands/api_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class APISubCommand<T extends APIResponse> extends BaseCommand {
APISubCommand() {
argParser.addFlag(
'compress',
abbr: 'c',
help: 'Prints JSON with no whitespace',
negatable: false,
);
Expand Down
148 changes: 148 additions & 0 deletions test/models/flutter_version_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,152 @@ void main() {
expect(afterUnsorted, sortedList);
});
});

group('FlutterVersion', () {
test('fromMap constructor', () {
final map = {
'name': 'test',
'releaseFromChannel': 'stable',
'type': 'release',
};
final version = FlutterVersion.fromMap(map);
expect(version.name, 'test');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('fromJson constructor', () {
final json =
'{"name":"test","releaseFromChannel":"stable","type":"release"}';
final version = FlutterVersion.fromJson(json);
expect(version.name, 'test');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('commit constructor', () {
final version = FlutterVersion.commit('abc123');
expect(version.name, 'abc123');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.commit);
});

test('channel constructor', () {
final version = FlutterVersion.channel('stable');
expect(version.name, 'stable');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.channel);
});

test('custom constructor', () {
final version = FlutterVersion.custom('custom_123');
expect(version.name, 'custom_123');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.custom);
});

test('release constructor', () {
final version =
FlutterVersion.release('1.0.0', releaseFromChannel: 'stable');
expect(version.name, '1.0.0');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('parse method - release version', () {
final version = FlutterVersion.parse('1.0.0');
expect(version.name, '1.0.0');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.release);
});

test('parse method - release version with channel', () {
final version = FlutterVersion.parse('1.0.0@stable');
expect(version.name, '1.0.0@stable');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('parse method - custom version', () {
final version = FlutterVersion.parse('custom_123');
expect(version.name, 'custom_123');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.custom);
});

test('parse method - commit version', () {
final version = FlutterVersion.parse('f4c74a6ec3');
expect(version.name, 'f4c74a6ec3');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.commit);
});

test('parse method - channel version', () {
final version = FlutterVersion.parse('stable');
expect(version.name, 'stable');
expect(version.releaseFromChannel, isNull);
expect(version.type, VersionType.channel);
});

test('parse method - invalid version format', () {
expect(
() => FlutterVersion.parse('1.0.0@invalid'), throwsFormatException);
});

test('version getter', () {
final version = FlutterVersion.release('1.0.0@stable');
expect(version.version, '1.0.0');
});

test('isMaster getter', () {
final version1 = FlutterVersion.channel('master');
expect(version1.isMaster, isTrue);

final version2 = FlutterVersion.channel('stable');
expect(version2.isMaster, isFalse);
});

test('isChannel getter', () {
final version = FlutterVersion.channel('stable');
expect(version.isChannel, isTrue);
});

test('isRelease getter', () {
final version = FlutterVersion.release('1.0.0');
expect(version.isRelease, isTrue);
});

test('isCommit getter', () {
final version = FlutterVersion.commit('abc123');
expect(version.isCommit, isTrue);
});

test('isCustom getter', () {
final version = FlutterVersion.custom('custom_123');
expect(version.isCustom, isTrue);
});

test('printFriendlyName getter - channel version', () {
final version = FlutterVersion.channel('stable');
expect(version.printFriendlyName, 'Channel: Stable');
});

test('printFriendlyName getter - commit version', () {
final version = FlutterVersion.commit('abc123');
expect(version.printFriendlyName, 'Commit : abc123');
});

test('printFriendlyName getter - release version', () {
final version = FlutterVersion.release('1.0.0');
expect(version.printFriendlyName, 'SDK Version : 1.0.0');
});

test('compareTo method', () {
final version1 = FlutterVersion.release('1.0.0');
final version2 = FlutterVersion.release('2.0.0');
expect(version1.compareTo(version2), lessThan(0));
expect(version2.compareTo(version1), greaterThan(0));
expect(version1.compareTo(version1), equals(0));
});
});
}
153 changes: 153 additions & 0 deletions test/src/models/cache_flutter_version_model_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import 'dart:io';

import 'package:fvm/fvm.dart';
import 'package:fvm/src/models/flutter_version_model.dart';
import 'package:test/test.dart';

void main() {
group('CacheFlutterVersion', () {
test('fromMap constructor', () {
final map = {
'name': 'test',
'directory': '/path/to/cache',
'releaseFromChannel': 'stable',
'type': 'release',
};
final version = CacheFlutterVersion.fromMap(map);
expect(version.name, 'test');
expect(version.directory, '/path/to/cache');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('fromJson constructor', () {
final json =
'{"name":"test","directory":"/path/to/cache","releaseFromChannel":"stable","type":"release"}';
final version = CacheFlutterVersion.fromJson(json);
expect(version.name, 'test');
expect(version.directory, '/path/to/cache');
expect(version.releaseFromChannel, 'stable');
expect(version.type, VersionType.release);
});

test('constructor', () {
final flutterVersion = FlutterVersion.release('1.0.0');
final cacheVersion =
CacheFlutterVersion(flutterVersion, directory: '/path/to/cache');
expect(cacheVersion.name, '1.0.0');
expect(cacheVersion.directory, '/path/to/cache');
expect(cacheVersion.releaseFromChannel, isNull);
expect(cacheVersion.type, VersionType.release);
});

test('binPath getter', () {
final version = CacheFlutterVersion.raw('test',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version.binPath, '/path/to/cache/bin');
});

test('hasOldBinPath getter', () {
final version1 = CacheFlutterVersion.raw('1.17.5',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version1.hasOldBinPath, isTrue);

final version2 = CacheFlutterVersion.raw('2.0.0',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version2.hasOldBinPath, isFalse);
});

test('dartBinPath getter', () {
final version1 = CacheFlutterVersion.raw('1.17.5',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version1.dartBinPath, '/path/to/cache/bin/cache/dart-sdk/bin');

final version2 = CacheFlutterVersion.raw('2.0.0',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version2.dartBinPath, '/path/to/cache/bin');
});

test('dartExec getter', () {
final version = CacheFlutterVersion.raw('2.0.0',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version.dartExec, '/path/to/cache/bin/dart');
});

test('flutterExec getter', () {
final version = CacheFlutterVersion.raw('test',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version.flutterExec, '/path/to/cache/bin/flutter');
});

test('flutterSdkVersion getter', () {
// Create a temporary directory for testing
final tempDir = Directory.systemTemp.createTempSync('cache_version_test');
final versionFile = File('${tempDir.path}/version');
versionFile.writeAsStringSync('1.0.0');

final version = CacheFlutterVersion.raw('test',
directory: tempDir.path,
releaseFromChannel: null,
type: VersionType.release);
expect(version.flutterSdkVersion, '1.0.0');

// Clean up the temporary directory
tempDir.deleteSync(recursive: true);
});

test('dartSdkVersion getter', () {
// Create a temporary directory for testing
final tempDir = Directory.systemTemp.createTempSync('cache_version_test');
final dartSdkDir = Directory('${tempDir.path}/bin/cache/dart-sdk');
dartSdkDir.createSync(recursive: true);
final versionFile = File('${dartSdkDir.path}/version');
versionFile.writeAsStringSync('2.12.0');

final version = CacheFlutterVersion.raw('test',
directory: tempDir.path,
releaseFromChannel: null,
type: VersionType.release);
expect(version.dartSdkVersion, '2.12.0');

// Clean up the temporary directory
tempDir.deleteSync(recursive: true);
});

test('isNotSetup getter', () {
final version = CacheFlutterVersion.raw('test',
directory: '/path/to/cache',
releaseFromChannel: null,
type: VersionType.release);
expect(version.isNotSetup, isTrue);
});

test('isSetup getter', () {
// Create a temporary directory for testing
final tempDir = Directory.systemTemp.createTempSync('cache_version_test');
final versionFile = File('${tempDir.path}/version');
versionFile.writeAsStringSync('1.0.0');

final version = CacheFlutterVersion.raw('test',
directory: tempDir.path,
releaseFromChannel: null,
type: VersionType.release);
expect(version.isSetup, isTrue);

// Clean up the temporary directory
tempDir.deleteSync(recursive: true);
});
});
}

0 comments on commit 0537065

Please sign in to comment.