Init initializes test data - Setup a new upstream repo in a tmp directory - Set the initial upstream content to Dataset1 - Setup a new cache location for git repos and update the environment variable - Setup fetch the upstream package to a local package - Verify the local package contains the upstre
(dataset string)
| 72 | // - Setup fetch the upstream package to a local package |
| 73 | // - Verify the local package contains the upstream content |
| 74 | func (g *TestSetupManager) Init(dataset string) bool { |
| 75 | // Default optional values |
| 76 | if g.GetRef == "" { |
| 77 | g.GetRef = "master" |
| 78 | } |
| 79 | if g.GetSubDirectory == "" { |
| 80 | g.GetSubDirectory = "/" |
| 81 | } |
| 82 | |
| 83 | // Configure the cache location for cloning repos |
| 84 | cacheDir, err := ioutil.TempDir("", "kpt-test-cache-repos-") |
| 85 | if !assert.NoError(g.T, err) { |
| 86 | return false |
| 87 | } |
| 88 | g.cacheDir = cacheDir |
| 89 | os.Setenv(gitutil.RepoCacheDirEnv, g.cacheDir) |
| 90 | |
| 91 | // Setup a "remote" source repo, and a "local" destination repo |
| 92 | g.UpstreamRepo, g.LocalWorkspace, g.cleanTestRepo = SetupDefaultRepoAndWorkspace(g.T, dataset) |
| 93 | if g.GetSubDirectory == "/" { |
| 94 | g.targetDir = filepath.Base(g.UpstreamRepo.RepoName) |
| 95 | } else { |
| 96 | g.targetDir = filepath.Base(g.GetSubDirectory) |
| 97 | } |
| 98 | if !assert.NoError(g.T, os.Chdir(g.UpstreamRepo.RepoDirectory)) { |
| 99 | return false |
| 100 | } |
| 101 | |
| 102 | if err := updateGitDir(g.T, g.UpstreamRepo, g.UpstreamInit); err != nil { |
| 103 | return false |
| 104 | } |
| 105 | |
| 106 | // Fetch the source repo |
| 107 | if !assert.NoError(g.T, os.Chdir(g.LocalWorkspace.WorkspaceDirectory)) { |
| 108 | return false |
| 109 | } |
| 110 | |
| 111 | if !assert.NoError(g.T, get.Command{ |
| 112 | Destination: g.targetDir, |
| 113 | Git: kptfile.Git{ |
| 114 | Repo: g.UpstreamRepo.RepoDirectory, |
| 115 | Ref: g.GetRef, |
| 116 | Directory: g.GetSubDirectory, |
| 117 | }}.Run()) { |
| 118 | return false |
| 119 | } |
| 120 | localGit := gitutil.NewLocalGitRunner(g.LocalWorkspace.WorkspaceDirectory) |
| 121 | if !assert.NoError(g.T, localGit.Run("add", ".")) { |
| 122 | return false |
| 123 | } |
| 124 | if !assert.NoError(g.T, localGit.Run("commit", "-m", "add files")) { |
| 125 | return false |
| 126 | } |
| 127 | |
| 128 | // Modify source repository state after fetching it |
| 129 | if err := updateGitDir(g.T, g.UpstreamRepo, g.UpstreamChanges); err != nil { |
| 130 | return false |
| 131 | } |