2
* ALR - Any Linux Repository
3
* Copyright (C) 2024 Евгений Храмов
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
30
"plemya-x.ru/alr/internal/config"
31
"plemya-x.ru/alr/internal/dlcache"
35
dir, err := os.MkdirTemp("/tmp", "alr-dlcache-test.*")
39
config.GetPaths(context.Background()).RepoDir = dir
42
func TestNew(t *testing.T) {
43
const id = "https://example.com"
44
dir, err := dlcache.New(id)
46
t.Errorf("Expected no error, got %s", err)
49
exp := filepath.Join(dlcache.BasePath(), sha1sum(id))
51
t.Errorf("Expected %s, got %s", exp, dir)
54
fi, err := os.Stat(dir)
56
t.Errorf("stat: expected no error, got %s", err)
60
t.Errorf("Expected cache item to be a directory")
63
dir2, ok := dlcache.Get(id)
65
t.Errorf("Expected Get() to return valid value")
68
t.Errorf("Expected %s from Get(), got %s", dir, dir2)
72
func sha1sum(id string) string {
74
_, _ = io.WriteString(h, id)
75
return hex.EncodeToString(h.Sum(nil))