TestCommand_Run_clean verifies that the Command delete the existing directory if Clean is set. 1. clone the master branch 2. add data to the master branch and commit it 3. clone the master branch again 4. verify the new master branch data is present
(t *testing.T)
| 351 | // 3. clone the master branch again |
| 352 | // 4. verify the new master branch data is present |
| 353 | func TestCommand_Run_clean(t *testing.T) { |
| 354 | g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1) |
| 355 | defer clean() |
| 356 | |
| 357 | err := Command{ |
| 358 | Git: kptfile.Git{Repo: g.RepoDirectory, Ref: "master", Directory: "/"}, |
| 359 | Destination: filepath.Base(g.RepoDirectory)}.Run() |
| 360 | assert.NoError(t, err) |
| 361 | |
| 362 | // verify the KptFile contains the expected values |
| 363 | commit, err := g.GetCommit() |
| 364 | assert.NoError(t, err) |
| 365 | |
| 366 | // verify the cloned contents matches the repository |
| 367 | r := filepath.Join(w.WorkspaceDirectory, g.RepoName) |
| 368 | g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), r) |
| 369 | |
| 370 | g.AssertKptfile(t, r, kptfile.KptFile{ |
| 371 | ResourceMeta: yaml.ResourceMeta{ |
| 372 | ObjectMeta: yaml.ObjectMeta{ |
| 373 | NameMeta: yaml.NameMeta{ |
| 374 | Name: g.RepoName, |
| 375 | }, |
| 376 | }, |
| 377 | TypeMeta: yaml.TypeMeta{ |
| 378 | APIVersion: kptfile.TypeMeta.APIVersion, |
| 379 | Kind: kptfile.TypeMeta.Kind}, |
| 380 | }, |
| 381 | PackageMeta: kptfile.PackageMeta{}, |
| 382 | Upstream: kptfile.Upstream{ |
| 383 | Type: "git", |
| 384 | Git: kptfile.Git{ |
| 385 | Directory: "/", |
| 386 | Repo: g.RepoDirectory, |
| 387 | Ref: "master", |
| 388 | Commit: commit, // verify the commit matches the repo |
| 389 | }, |
| 390 | }, |
| 391 | }) |
| 392 | |
| 393 | // update the data that would be cloned |
| 394 | err = g.ReplaceData(testutil.Dataset2) |
| 395 | assert.NoError(t, err) |
| 396 | err = g.Commit("new-data") |
| 397 | assert.NoError(t, err) |
| 398 | |
| 399 | // verify the KptFile contains the expected values |
| 400 | commit, err = g.GetCommit() |
| 401 | assert.NoError(t, err) |
| 402 | |
| 403 | // configure clone to clean the existing dir |
| 404 | err = Command{ |
| 405 | Git: kptfile.Git{Repo: g.RepoDirectory, Ref: "master", Directory: "/"}, |
| 406 | Destination: filepath.Base(g.RepoDirectory), Clean: true}.Run() |
| 407 | assert.NoError(t, err) |
| 408 | |
| 409 | // verify files are updated |
| 410 | g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset2), r) |
nothing calls this directly
no test coverage detected