TestGenIdentifier 测试标识符生成
(t *testing.T)
| 154 | |
| 155 | // TestGenIdentifier 测试标识符生成 |
| 156 | func TestGenIdentifier(t *testing.T) { |
| 157 | tests := []struct { |
| 158 | name string |
| 159 | host string |
| 160 | expectedH byte |
| 161 | expectedL byte |
| 162 | shouldRun bool |
| 163 | }{ |
| 164 | { |
| 165 | name: "正常IP地址", |
| 166 | host: "192.168.1.1", |
| 167 | expectedH: '1', |
| 168 | expectedL: '9', |
| 169 | shouldRun: true, |
| 170 | }, |
| 171 | { |
| 172 | name: "域名", |
| 173 | host: "example.com", |
| 174 | expectedH: 'e', |
| 175 | expectedL: 'x', |
| 176 | shouldRun: true, |
| 177 | }, |
| 178 | { |
| 179 | name: "两字符最小长度", |
| 180 | host: "ab", |
| 181 | expectedH: 'a', |
| 182 | expectedL: 'b', |
| 183 | shouldRun: true, |
| 184 | }, |
| 185 | } |
| 186 | |
| 187 | for _, tt := range tests { |
| 188 | t.Run(tt.name, func(t *testing.T) { |
| 189 | if !tt.shouldRun { |
| 190 | t.Skip("跳过可能panic的测试") |
| 191 | } |
| 192 | |
| 193 | h, l := genIdentifier(tt.host) |
| 194 | if h != tt.expectedH || l != tt.expectedL { |
| 195 | t.Errorf("genIdentifier(%q) = (%c, %c), 期望 (%c, %c)", |
| 196 | tt.host, h, l, tt.expectedH, tt.expectedL) |
| 197 | } |
| 198 | }) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // TestGenIdentifier_EdgeCases 测试genIdentifier边界情况(修复后) |
| 203 | func TestGenIdentifier_EdgeCases(t *testing.T) { |
nothing calls this directly
no test coverage detected