Skip to content

Commit

Permalink
Automatic Revert (Part 3): Add supporting test files for the automati…
Browse files Browse the repository at this point in the history
…c revert feature (#3085)

Add supporting fake classes for testing and a new field for the autosubmit query result.

*List which issues are fixed by this PR. You must list at least one issue.*
Part of flutter/flutter#113867

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
  • Loading branch information
ricardoamador authored Sep 20, 2023
1 parent cc2034e commit 704ad31
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions auto_submit/lib/model/auto_submit_query_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class PullRequest {
this.reviews,
this.commits,
this.mergeable,
this.number,
});
final Author? author;
@JsonKey(name: 'authorAssociation')
Expand All @@ -155,6 +156,7 @@ class PullRequest {
final String? body;
final Reviews? reviews;
final Commits? commits;
final int? number;
// https://docs.github.com/en/graphql/reference/enums#mergeablestate
final MergeableState? mergeable;

Expand Down
2 changes: 2 additions & 0 deletions auto_submit/lib/model/auto_submit_query_result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions auto_submit/test/src/validations/fake_approval.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:auto_submit/model/auto_submit_query_result.dart';

import 'package:auto_submit/validations/approval.dart';
import 'package:auto_submit/validations/validation.dart';
import 'package:github/github.dart' as github;

class FakeApproval extends Approval {
FakeApproval({required super.config});

ValidationResult? validationResult;

@override
String get name => 'FakeApproval';

/// Implements the code review approval logic.
@override
Future<ValidationResult> validate(QueryResult result, github.PullRequest messagePullRequest) async {
return validationResult ?? ValidationResult(true, Action.REMOVE_LABEL, '');
}
}
22 changes: 22 additions & 0 deletions auto_submit/test/src/validations/fake_mergeable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:auto_submit/model/auto_submit_query_result.dart';
import 'package:auto_submit/validations/mergeable.dart';
import 'package:auto_submit/validations/validation.dart';
import 'package:github/github.dart' as github;

class FakeMergeable extends Mergeable {
FakeMergeable({required super.config});

ValidationResult? validationResult;

@override
String get name => 'FakeMergeable';

@override
Future<ValidationResult> validate(QueryResult result, github.PullRequest messagePullRequest) async {
return validationResult ?? ValidationResult(true, Action.REMOVE_LABEL, '');
}
}
23 changes: 23 additions & 0 deletions auto_submit/test/src/validations/fake_required_check_runs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:auto_submit/validations/required_check_runs.dart';
import 'package:auto_submit/model/auto_submit_query_result.dart' as auto;

import 'package:auto_submit/validations/validation.dart';
import 'package:github/github.dart' as github;

class FakeRequiredCheckRuns extends RequiredCheckRuns {
FakeRequiredCheckRuns({required super.config});

ValidationResult? validationResult;

@override
String get name => 'FakeRequiredCheckRuns';

@override
Future<ValidationResult> validate(auto.QueryResult result, github.PullRequest messagePullRequest) async {
return validationResult ?? ValidationResult(true, Action.REMOVE_LABEL, '');
}
}
19 changes: 19 additions & 0 deletions auto_submit/test/src/validations/fake_validation_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:auto_submit/validations/validation.dart';
import 'package:auto_submit/validations/validation_filter.dart';

class FakeValidationFilter implements ValidationFilter {
final Set<Validation> validations = {};

void registerValidation(Validation newValidation) {
validations.add(newValidation);
}

@override
Set<Validation> getValidations() {
return validations;
}
}

0 comments on commit 704ad31

Please sign in to comment.