|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:github/github.dart'; |
| 4 | +import 'package:test/test.dart'; |
| 5 | + |
| 6 | +/// Opt-in safe live smoke test suite. |
| 7 | +/// |
| 8 | +/// Runs only when GITHUB_TOKEN or GITHUB_LIVE_SMOKE=1 is set in the environment. |
| 9 | +/// Executes only safe, non-destructive read operations against public GitHub endpoints. |
| 10 | +void main() { |
| 11 | + final hasToken = Platform.environment.containsKey('GITHUB_TOKEN') || |
| 12 | + Platform.environment['GITHUB_LIVE_SMOKE'] == '1'; |
| 13 | + |
| 14 | + group('Live GitHub API Smoke Tests (Read-Only)', () { |
| 15 | + late GitHub github; |
| 16 | + |
| 17 | + setUp(() { |
| 18 | + final token = Platform.environment['GITHUB_TOKEN']; |
| 19 | + github = GitHub( |
| 20 | + auth: token != null |
| 21 | + ? Authentication.withToken(token) |
| 22 | + : const Authentication.anonymous(), |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + tearDown(() { |
| 27 | + github.dispose(); |
| 28 | + }); |
| 29 | + |
| 30 | + test('fetches public repository metadata', () async { |
| 31 | + final repo = await github.repositories |
| 32 | + .getRepository(RepositorySlug('octocat', 'Hello-World')); |
| 33 | + |
| 34 | + expect(repo.name, equals('Hello-World')); |
| 35 | + expect(repo.owner?.login, equals('octocat')); |
| 36 | + }); |
| 37 | + |
| 38 | + test('fetches API status from status endpoint', () async { |
| 39 | + final status = await github.misc.getApiStatus(); |
| 40 | + expect(status.status, isNotNull); |
| 41 | + expect(status.status?.indicator, isNotNull); |
| 42 | + }); |
| 43 | + |
| 44 | + test('fetches zen message', () async { |
| 45 | + final zen = await github.misc.getZen(); |
| 46 | + expect(zen, isNotEmpty); |
| 47 | + }); |
| 48 | + |
| 49 | + test('fetches gitignore templates list', () async { |
| 50 | + final templates = await github.misc.listGitignoreTemplates(); |
| 51 | + expect(templates, contains('Dart')); |
| 52 | + }); |
| 53 | + }, |
| 54 | + skip: !hasToken |
| 55 | + ? 'Skipped: Set GITHUB_TOKEN or GITHUB_LIVE_SMOKE=1 to run safe live tests.' |
| 56 | + : null); |
| 57 | +} |
0 commit comments