TestCmd_execute verifies that update is correctly invoked.
(t *testing.T)
| 34 | |
| 35 | // TestCmd_execute verifies that update is correctly invoked. |
| 36 | func TestCmd_execute(t *testing.T) { |
| 37 | g, w, clean := testutil.SetupDefaultRepoAndWorkspace(t, testutil.Dataset1) |
| 38 | defer clean() |
| 39 | dest := filepath.Join(w.WorkspaceDirectory, g.RepoName) |
| 40 | |
| 41 | // clone the repo |
| 42 | getCmd := cmdget.NewRunner("kpt") |
| 43 | getCmd.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git", w.WorkspaceDirectory}) |
| 44 | err := getCmd.Command.Execute() |
| 45 | if !assert.NoError(t, err) { |
| 46 | return |
| 47 | } |
| 48 | if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), dest) { |
| 49 | return |
| 50 | } |
| 51 | gitRunner := gitutil.NewLocalGitRunner(w.WorkspaceDirectory) |
| 52 | if !assert.NoError(t, gitRunner.Run("add", ".")) { |
| 53 | return |
| 54 | } |
| 55 | if !assert.NoError(t, gitRunner.Run("commit", "-m", "commit local package -- ds1")) { |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | // update the master branch |
| 60 | if !assert.NoError(t, g.ReplaceData(testutil.Dataset2)) { |
| 61 | return |
| 62 | } |
| 63 | if !assert.NoError(t, g.Commit("modify upstream package -- ds2")) { |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | // update the cloned package |
| 68 | updateCmd := cmdupdate.NewRunner("kpt") |
| 69 | if !assert.NoError(t, os.Chdir(w.WorkspaceDirectory)) { |
| 70 | return |
| 71 | } |
| 72 | updateCmd.Command.SetArgs([]string{g.RepoName, "--strategy", "fast-forward"}) |
| 73 | if !assert.NoError(t, updateCmd.Command.Execute()) { |
| 74 | return |
| 75 | } |
| 76 | if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset2), dest) { |
| 77 | return |
| 78 | } |
| 79 | |
| 80 | commit, err := g.GetCommit() |
| 81 | if !assert.NoError(t, err) { |
| 82 | return |
| 83 | } |
| 84 | if !g.AssertKptfile(t, dest, kptfile.KptFile{ |
| 85 | ResourceMeta: yaml.ResourceMeta{ |
| 86 | ObjectMeta: yaml.ObjectMeta{ |
| 87 | NameMeta: yaml.NameMeta{ |
| 88 | Name: g.RepoName, |
| 89 | }, |
| 90 | }, |
| 91 | TypeMeta: yaml.TypeMeta{ |
| 92 | APIVersion: kptfile.TypeMeta.APIVersion, |
| 93 | Kind: kptfile.TypeMeta.Kind}, |
nothing calls this directly
no test coverage detected