Skip to content

Commit 92dc47d

Browse files
committed
refactor: テストファイルをtest/integrationディレクトリに整理
変更内容: - scripts/utils/test_*.rb を test/integration/ に移動 - 統合テスト(実際のAPI呼び出し)を明確に分離 - require_relative パスを修正 - test/README.md を追加してテスト構造を文書化 ディレクトリ構造: - test/ # ユニットテスト - csv_test.rb - ip_validation_test.rb - test/integration/ # 統合テスト(実際のAPI使用) - test_regex_patterns.rb - test_server_with_notes.rb - test_with_packet_filter.rb - test_with_startup_script.rb これにより、テストの種類が明確になり、保守性が向上
1 parent 83d130c commit 92dc47d

File tree

5 files changed

+101
-3
lines changed

5 files changed

+101
-3
lines changed

test/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# テストディレクトリ構成
2+
3+
## ディレクトリ構造
4+
5+
```
6+
test/
7+
├── README.md # このファイル
8+
├── csv_test.rb # CSVフォーマットのバリデーションテスト
9+
├── ip_validation_test.rb # IPアドレス検証のテスト
10+
└── integration/ # 統合テスト・実際のAPI呼び出しテスト
11+
├── test_regex_patterns.rb # 正規表現パターンのテスト
12+
├── test_server_with_notes.rb # スタートアップスクリプト実行テスト
13+
├── test_with_packet_filter.rb # パケットフィルター適用テスト
14+
└── test_with_startup_script.rb # スタートアップスクリプトテスト
15+
```
16+
17+
## テストの種類
18+
19+
### ユニットテスト(`test/`直下)
20+
21+
- **csv_test.rb**: `servers.csv`のフォーマットを検証
22+
- ヘッダーの存在確認
23+
- 必須フィールドのチェック
24+
- SSH公開鍵の形式検証
25+
26+
- **ip_validation_test.rb**: IPアドレス検証機能のテスト
27+
- 有効/無効なIPアドレスのテストケース
28+
- 正規化処理のテスト
29+
30+
### 統合テスト(`test/integration/`
31+
32+
実際のさくらのクラウドAPIと連携するテスト。**本番環境では実行しないでください。**
33+
34+
- **test_with_packet_filter.rb**: 本番環境設定でのサーバー作成テスト
35+
- パケットフィルター(ファイアウォール)の適用確認
36+
- ポート22, 80, 443の開放確認
37+
38+
- **test_with_startup_script.rb**: スタートアップスクリプトのテスト
39+
- スクリプトID: 112900928939の実行確認
40+
- iptables設定、SSH強化設定の適用確認
41+
42+
- **test_server_with_notes.rb**: Notes APIフィールドのデバッグ
43+
- disk/config APIでのNotes設定動作確認
44+
- サーバー起動時のNotes指定確認
45+
46+
- **test_regex_patterns.rb**: Issue解析用正規表現のテスト
47+
- CoderDojo名の抽出パターン
48+
- IPアドレスの抽出パターン
49+
50+
## テストの実行方法
51+
52+
### ユニットテスト
53+
54+
```bash
55+
# CSVフォーマットテスト
56+
bundle exec ruby test/csv_test.rb
57+
58+
# IPアドレス検証テスト
59+
bundle exec ruby test/ip_validation_test.rb
60+
61+
# すべてのユニットテスト
62+
bundle exec rake test
63+
```
64+
65+
### 統合テスト
66+
67+
⚠️ **警告**: これらのテストは実際のリソースを作成する可能性があります。
68+
69+
```bash
70+
# 環境変数の設定が必要
71+
export SACLOUD_ACCESS_TOKEN=xxxx
72+
export SACLOUD_ACCESS_TOKEN_SECRET=xxxx
73+
export SSH_PUBLIC_KEY_PATH=~/.ssh/id_rsa.pub
74+
75+
# 個別実行(テスト環境のみ)
76+
ruby test/integration/test_with_packet_filter.rb test-server
77+
ruby test/integration/test_with_startup_script.rb test-server
78+
```
79+
80+
## 注意事項
81+
82+
1. **統合テストは本番環境で実行しない**
83+
- 実際のサーバーが作成される
84+
- 課金が発生する可能性がある
85+
86+
2. **API認証情報が必要**
87+
- `SACLOUD_ACCESS_TOKEN`
88+
- `SACLOUD_ACCESS_TOKEN_SECRET`
89+
90+
3. **SSH公開鍵が必要**
91+
- デフォルト: `~/.ssh/id_rsa.pub`
92+
- 環境変数: `SSH_PUBLIC_KEY_PATH`
93+
94+
## 関連ドキュメント
95+
96+
- [セキュリティ設計](../docs/security-defense-in-depth.md)
97+
- [サーバー初期化手順](../docs/initialize-server.md)
98+
- [SSH接続設定](../docs/ssh.md)
File renamed without changes.

scripts/utils/test_server_with_notes.rb renamed to test/integration/test_server_with_notes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# 通常版Ubuntuでdisk/config APIのNotesフィールドが機能するか確認
55

66
require 'dotenv/load'
7-
require_relative '../sakura_server_user_agent.rb'
7+
require_relative '../../scripts/sakura_server_user_agent.rb'
88

99
if ARGV.length < 1
1010
puts "使用方法: ruby #{$0} <サーバー名>"

scripts/utils/test_with_packet_filter.rb renamed to test/integration/test_with_packet_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# 通常版Ubuntu 24.04 + disk/config API + @notes + パケットフィルター
55

66
require 'dotenv/load'
7-
require_relative '../sakura_server_user_agent.rb'
7+
require_relative '../../scripts/sakura_server_user_agent.rb'
88

99
# SSH公開鍵を読み込み
1010
ssh_public_key_path = ENV['SSH_PUBLIC_KEY_PATH'] || File.expand_path('~/.ssh/id_rsa.pub')

scripts/utils/test_with_startup_script.rb renamed to test/integration/test_with_startup_script.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# デフォルトでSTARTUP_SCRIPT_IDが設定される
55

66
require 'dotenv/load'
7-
require_relative '../sakura_server_user_agent.rb'
7+
require_relative '../../scripts/sakura_server_user_agent.rb'
88

99
# SSH公開鍵を読み込み
1010
ssh_public_key_path = ENV['SSH_PUBLIC_KEY_PATH'] || File.expand_path('~/.ssh/id_rsa.pub')

0 commit comments

Comments
 (0)