Skip to content

test: add a test for shorebird.yaml compiling that uses disk #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/shorebird_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
# TODO(eseidel): We can't run all flutter_tools tests until we make
# our changes not throw exceptions on missing shorebird.yaml.
# https://github.com/shorebirdtech/shorebird/issues/2392
run: ../../bin/flutter test test/general.shard/shorebird
working-directory: packages/flutter_tools

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ Future<XcodeBuildResult> buildXcodeProject({
}

try {
updateShorebirdYaml(buildInfo, app.shorebirdYamlPath);
updateShorebirdYaml(buildInfo, app.shorebirdYamlPath, environment: globals.platform.environment);
} on Exception catch (error) {
globals.printError('[shorebird] failed to generate shorebird configuration.\n$error');
return XcodeBuildResult(success: false);
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/shorebird/shorebird_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import '../base/file_system.dart';
import '../build_info.dart';
import '../globals.dart' as globals;

void updateShorebirdYaml(BuildInfo buildInfo, String shorebirdYamlPath) {
void updateShorebirdYaml(BuildInfo buildInfo, String shorebirdYamlPath, {required Map<String, String> environment}) {
final File shorebirdYaml = globals.fs.file(shorebirdYamlPath);
if (!shorebirdYaml.existsSync()) {
throw Exception('shorebird.yaml not found at $shorebirdYamlPath');
}
final YamlDocument input = loadYamlDocument(shorebirdYaml.readAsStringSync());
final YamlMap yamlMap = input.contents as YamlMap;
final Map<String, dynamic> compiled = compileShorebirdYaml(yamlMap, flavor: buildInfo.flavor, environment: globals.platform.environment);
final Map<String, dynamic> compiled = compileShorebirdYaml(yamlMap, flavor: buildInfo.flavor, environment: environment);
// Currently we write out over the same yaml file, we should fix this to
// write to a new .json file instead and avoid naming confusion between the
// input and compiled files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/shorebird/shorebird_yaml.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
Expand Down Expand Up @@ -69,5 +72,27 @@ base_url: https://example.com
'patch_public_key': '4-a',
});
});
test('edit in place', () {
const String yamlContents = '''
app_id: 1-a
auto_update: false
flavors:
foo: 2-a
bar: 3-a
base_url: https://example.com
''';
// Make a temporary file to test editing in place.
final Directory tempDir = Directory.systemTemp.createTempSync('shorebird_yaml_test.');
final File tempFile = File('${tempDir.path}/shorebird.yaml');
tempFile.writeAsStringSync(yamlContents);
updateShorebirdYaml(const BuildInfo(BuildMode.release, 'foo', treeShakeIcons: false), tempFile.path, environment: <String, String>{'SHOREBIRD_PUBLIC_KEY': '4-a'});
final String updatedContents = tempFile.readAsStringSync();
// Order is not guaranteed, so parse as YAML to compare.
final YamlDocument updated = loadYamlDocument(updatedContents);
final YamlMap yamlMap = updated.contents as YamlMap;
expect(yamlMap['app_id'], '2-a');
expect(yamlMap['auto_update'], false);
expect(yamlMap['base_url'], 'https://example.com');
});
});
}
Loading