MCPcopy
hub / github.com/zarf-dev/zarf / TestRepository

Function TestRepository

src/internal/git/repository_test.go:28–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestRepository(t *testing.T) {
29 t.Parallel()
30 ctx := testutil.TestContext(t)
31
32 cfg := gitkit.Config{
33 Dir: t.TempDir(),
34 AutoCreate: true,
35 }
36 gitSrv := gitkit.New(cfg)
37 err := gitSrv.Setup()
38 require.NoError(t, err)
39 srv := httptest.NewServer(http.HandlerFunc(gitSrv.ServeHTTP))
40 t.Cleanup(func() {
41 srv.Close()
42 })
43
44 rootPath := t.TempDir()
45 repoName := "test"
46 repoAddress := fmt.Sprintf("%s/%s.git", srv.URL, repoName)
47 checksum := helpers.GetCRCHash(repoAddress)
48 expectedPath := fmt.Sprintf("%s-%d", repoName, checksum)
49
50 storer := memory.NewStorage()
51 fs := memfs.New()
52 options := git.InitOptions{
53 DefaultBranch: plumbing.Main,
54 }
55 initRepo, err := git.InitWithOptions(storer, fs, options)
56 require.NoError(t, err)
57 w, err := initRepo.Worktree()
58 require.NoError(t, err)
59 filePath := "test.txt"
60 newFile, err := fs.Create(filePath)
61 require.NoError(t, err)
62 _, err = newFile.Write([]byte("Hello World"))
63 require.NoError(t, err)
64 err = newFile.Close()
65 require.NoError(t, err)
66 _, err = w.Add(filePath)
67 require.NoError(t, err)
68 _, err = w.Commit("Initial commit", &git.CommitOptions{
69 Author: &object.Signature{
70 Email: "example@example.com",
71 },
72 })
73 require.NoError(t, err)
74 _, err = initRepo.CreateRemote(&config.RemoteConfig{
75 Name: "origin",
76 URLs: []string{repoAddress},
77 })
78 require.NoError(t, err)
79 err = initRepo.Push(&git.PushOptions{
80 RemoteName: "origin",
81 })
82 require.NoError(t, err)
83
84 // TODO: Is there a configuration that defines contents of HEAD that isn't read from ~/.gitconfig
85 // Force-write refs/heads/main ref to HEAD to disk - Matching the above reference and decoupling from host gitconfig

Callers

nothing calls this directly

Calls 9

TestContextFunction · 0.92
CloneFunction · 0.85
OpenFunction · 0.85
CleanupMethod · 0.80
CloseMethod · 0.80
WriteMethod · 0.80
AddMethod · 0.80
PathMethod · 0.80
PushMethod · 0.45

Tested by

no test coverage detected