MCPcopy Create free account
hub / github.com/gogs/gogs / TestLocalStorage_Download

Function TestLocalStorage_Download

internal/lfsutil/storage_test.go:107–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

105}
106
107func TestLocalStorage_Download(t *testing.T) {
108 oid := OID("ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f")
109 s := &LocalStorage{
110 Root: filepath.Join(t.TempDir(), "lfs-objects"),
111 }
112
113 fpath := s.storagePath(oid)
114 err := os.MkdirAll(filepath.Dir(fpath), os.ModePerm)
115 if err != nil {
116 t.Fatal(err)
117 }
118 err = os.WriteFile(fpath, []byte("Hello world!"), os.ModePerm)
119 if err != nil {
120 t.Fatal(err)
121 }
122
123 tests := []struct {
124 name string
125 oid OID
126 expContent string
127 expErr error
128 }{
129 {
130 name: "object not exists",
131 oid: "bad_oid",
132 expErr: ErrObjectNotExist,
133 },
134
135 {
136 name: "valid oid",
137 oid: oid,
138 expContent: "Hello world!",
139 },
140 }
141 for _, test := range tests {
142 t.Run(test.name, func(t *testing.T) {
143 var buf bytes.Buffer
144 err := s.Download(test.oid, &buf)
145 assert.Equal(t, test.expContent, buf.String())
146 assert.Equal(t, test.expErr, err)
147 })
148 }
149}

Callers

nothing calls this directly

Calls 4

storagePathMethod · 0.95
DownloadMethod · 0.95
OIDTypeAlias · 0.85
StringMethod · 0.45

Tested by

no test coverage detected