From 569a49060724e9f43c267539e6f8c34ebf9b5ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=81=A5=E8=8E=B9?= Date: Tue, 26 Nov 2024 21:27:55 +0800 Subject: [PATCH] Add unit test for make outputArtifactPath --- .../lib/src/api/make_config.dart | 4 ++ packages/flutter_app_packager/pubspec.yaml | 1 + .../test/src/api/make_config_test.dart | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 packages/flutter_app_packager/test/src/api/make_config_test.dart diff --git a/packages/flutter_app_packager/lib/src/api/make_config.dart b/packages/flutter_app_packager/lib/src/api/make_config.dart index 52c42b6..e68097f 100644 --- a/packages/flutter_app_packager/lib/src/api/make_config.dart +++ b/packages/flutter_app_packager/lib/src/api/make_config.dart @@ -119,6 +119,10 @@ class MakeConfig { return _pubspec!; } + set pubspec(Pubspec pubspec) { + _pubspec = pubspec; + } + Map toJson() { return { 'isInstaller': isInstaller, diff --git a/packages/flutter_app_packager/pubspec.yaml b/packages/flutter_app_packager/pubspec.yaml index a60dd4b..e85cc29 100644 --- a/packages/flutter_app_packager/pubspec.yaml +++ b/packages/flutter_app_packager/pubspec.yaml @@ -21,3 +21,4 @@ dependencies: dev_dependencies: dependency_validator: ^3.0.0 mostly_reasonable_lints: ^0.1.2 + test: ^1.23.1 diff --git a/packages/flutter_app_packager/test/src/api/make_config_test.dart b/packages/flutter_app_packager/test/src/api/make_config_test.dart new file mode 100644 index 0000000..d11d6c5 --- /dev/null +++ b/packages/flutter_app_packager/test/src/api/make_config_test.dart @@ -0,0 +1,45 @@ +import 'dart:io'; + +import 'package:flutter_app_packager/src/api/make_config.dart'; +import 'package:pub_semver/pub_semver.dart'; +import 'package:pubspec_parse/pubspec_parse.dart'; +import 'package:test/test.dart'; + +void main() { + group('MakeConfig', () { + test('#1', () { + final makeConfig = MakeConfig() + ..buildMode = 'release' + ..buildOutputDirectory = Directory('build') + ..buildOutputFiles = [] + ..platform = 'android' + ..packageFormat = 'apk' + ..outputDirectory = Directory('dist/') + ..pubspec = Pubspec( + 'test_app', + version: Version.parse('1.0.0'), + ); + expect( + makeConfig.outputArtifactPath, + 'dist/1.0.0/test_app-1.0.0-android.apk', + ); + }); + test('#2', () { + final makeConfig = MakeConfig() + ..buildMode = 'release' + ..buildOutputDirectory = Directory('build') + ..buildOutputFiles = [] + ..platform = 'android' + ..packageFormat = 'apk' + ..outputDirectory = Directory('dist/') + ..pubspec = Pubspec( + 'test_app', + version: Version.parse('1.0.0+1'), + ); + expect( + makeConfig.outputArtifactPath, + 'dist/1.0.0+1/test_app-1.0.0+1-android.apk', + ); + }); + }); +}