// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved. This file is part of cc-backend.
// 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"

	"github.com/ClusterCockpit/cc-backend/pkg/archive"
	"github.com/ClusterCockpit/cc-lib/v2/schema"
	"github.com/ClusterCockpit/cc-lib/v2/util"
)

var jobs []*schema.Job

func setup(t *testing.T) archive.ArchiveBackend {
	tmpdir := t.TempDir()
	jobarchive := filepath.Join(tmpdir, "job-archive")
	util.CopyDir("./testdata/archive/", jobarchive)
	archiveCfg := fmt.Sprintf("{\"kind\": \"file\",\"path\": \"%s\"}", jobarchive)

	if err := archive.Init(json.RawMessage(archiveCfg)); 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 = 1608923076

	jobs[1] = &schema.Job{}
	jobs[0].JobID = 1404397
	jobs[0].Cluster = "emmy"
	jobs[0].StartTime = 1609300556

	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")
// 	}
// }
