2023-05-11 16:17:17 +02:00
|
|
|
// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package archive_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-05-12 15:09:39 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/internal/util"
|
2023-05-11 16:17:17 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/archive"
|
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
var jobs []*schema.Job
|
|
|
|
|
|
|
|
func setup(t *testing.T) archive.ArchiveBackend {
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
jobarchive := filepath.Join(tmpdir, "job-archive")
|
2023-05-12 15:09:39 +02:00
|
|
|
util.CopyDir("./testdata/archive/", jobarchive)
|
2023-05-11 16:17:17 +02:00
|
|
|
archiveCfg := fmt.Sprintf("{\"kind\": \"file\",\"path\": \"%s\"}", jobarchive)
|
|
|
|
|
|
|
|
if err := archive.Init(json.RawMessage(archiveCfg), false); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jobs = make([]*schema.Job, 2)
|
|
|
|
jobs[0] = &schema.Job{}
|
|
|
|
jobs[0].JobID = 1403244
|
|
|
|
jobs[0].Cluster = "emmy"
|
|
|
|
jobs[0].StartTime = time.Unix(1608923076, 0)
|
|
|
|
|
|
|
|
jobs[1] = &schema.Job{}
|
|
|
|
jobs[0].JobID = 1404397
|
|
|
|
jobs[0].Cluster = "emmy"
|
|
|
|
jobs[0].StartTime = time.Unix(1609300556, 0)
|
|
|
|
|
|
|
|
return archive.GetHandle()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCleanUp(t *testing.T) {
|
|
|
|
a := setup(t)
|
|
|
|
if !a.Exists(jobs[0]) {
|
|
|
|
t.Error("Job does not exist")
|
|
|
|
}
|
|
|
|
|
|
|
|
a.CleanUp(jobs)
|
|
|
|
|
|
|
|
if a.Exists(jobs[0]) || a.Exists(jobs[1]) {
|
|
|
|
t.Error("Jobs still exist")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// func TestCompress(t *testing.T) {
|
|
|
|
// a := setup(t)
|
|
|
|
// if !a.Exists(jobs[0]) {
|
|
|
|
// t.Error("Job does not exist")
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// a.Compress(jobs)
|
|
|
|
//
|
|
|
|
// if a.Exists(jobs[0]) || a.Exists(jobs[1]) {
|
|
|
|
// t.Error("Jobs still exist")
|
|
|
|
// }
|
|
|
|
// }
|