(t *testing.T)
| 315 | } |
| 316 | |
| 317 | func TestZpoolObjsetParsingWithSpace(t *testing.T) { |
| 318 | tests := []struct { |
| 319 | path string |
| 320 | expectedDataset string |
| 321 | }{ |
| 322 | { |
| 323 | path: "fixtures/proc/spl/kstat/zfs/pool1/objset-1", |
| 324 | expectedDataset: "pool1", |
| 325 | }, |
| 326 | { |
| 327 | path: "fixtures/proc/spl/kstat/zfs/pool1/objset-2", |
| 328 | expectedDataset: "pool1/dataset1", |
| 329 | }, |
| 330 | { |
| 331 | path: "fixtures/proc/spl/kstat/zfs/pool3/objset-1", |
| 332 | expectedDataset: "pool3", |
| 333 | }, |
| 334 | { |
| 335 | path: "fixtures/proc/spl/kstat/zfs/pool3/objset-2", |
| 336 | expectedDataset: "pool3/dataset with space", |
| 337 | }, |
| 338 | } |
| 339 | |
| 340 | c := zfsCollector{} |
| 341 | |
| 342 | var handlerCalled bool |
| 343 | for _, test := range tests { |
| 344 | file, err := os.Open(test.path) |
| 345 | if err != nil { |
| 346 | t.Fatal(err) |
| 347 | } |
| 348 | |
| 349 | handlerCalled = false |
| 350 | err = c.parsePoolObjsetFile(file, test.path, func(poolName string, datasetName string, s zfsSysctl, v uint64) { |
| 351 | handlerCalled = true |
| 352 | if test.expectedDataset != datasetName { |
| 353 | t.Fatalf("Incorrectly parsed dataset name: expected: '%s', got: '%s'", test.expectedDataset, datasetName) |
| 354 | } |
| 355 | }) |
| 356 | file.Close() |
| 357 | if err != nil { |
| 358 | t.Fatal(err) |
| 359 | } |
| 360 | if !handlerCalled { |
| 361 | t.Fatalf("Zpool parsing handler was not called for '%s'", test.path) |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | func TestZpoolObjsetParsing(t *testing.T) { |
| 367 | zpoolPaths, err := filepath.Glob("fixtures/proc/spl/kstat/zfs/*/objset-*") |
nothing calls this directly
no test coverage detected