(t *testing.T)
| 202 | } |
| 203 | |
| 204 | func TestIsSystemAccount(t *testing.T) { |
| 205 | conf := createConfFile(t, []byte(` |
| 206 | listen: 127.0.0.1:-1 |
| 207 | accounts: { |
| 208 | SYS: { |
| 209 | users: [ {user: "sys", password: "pass"} ] |
| 210 | } |
| 211 | APP: { |
| 212 | users: [ {user: "app", password: "pass"} ] |
| 213 | } |
| 214 | } |
| 215 | system_account: SYS |
| 216 | `)) |
| 217 | defer os.Remove(conf) |
| 218 | |
| 219 | s, _ := RunServerWithConfig(conf) |
| 220 | defer s.Shutdown() |
| 221 | |
| 222 | nc, err := nats.Connect(s.ClientURL(), nats.UserInfo("sys", "pass")) |
| 223 | if err != nil { |
| 224 | t.Fatalf("Error connecting: %v", err) |
| 225 | } |
| 226 | defer nc.Close() |
| 227 | |
| 228 | // IsSystemAccount is sent by the server in an async INFO after connect. |
| 229 | checkFor(t, time.Second, 15*time.Millisecond, func() error { |
| 230 | if !nc.IsSystemAccount() { |
| 231 | return fmt.Errorf("expected system account") |
| 232 | } |
| 233 | return nil |
| 234 | }) |
| 235 | |
| 236 | nc2, err := nats.Connect(s.ClientURL(), nats.UserInfo("app", "pass")) |
| 237 | if err != nil { |
| 238 | t.Fatalf("Error connecting: %v", err) |
| 239 | } |
| 240 | defer nc2.Close() |
| 241 | |
| 242 | if nc2.IsSystemAccount() { |
| 243 | t.Fatalf("Expected non-system account") |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | func TestMultipleClose(t *testing.T) { |
| 248 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected