Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

978 B
Raw Blame
package config

import (
	"errors"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGuestMetadataStore_SaveErrors(t *testing.T) {
	tempDir := t.TempDir()

	mfs := &mockFSError{FileSystem: defaultFileSystem{}, mkdirError: errors.New("mkdir error")}
	store := NewGuestMetadataStore(tempDir, mfs)

	// Trigger save via Set
	err := store.Set("id1", &GuestMetadata{LastKnownName: "test"})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "failed to create data directory")
}

func TestGuestMetadataStore_LoadErrors(t *testing.T) {
	tempDir := t.TempDir()

	mfs := &mockFSError{FileSystem: defaultFileSystem{}}
	store := NewGuestMetadataStore(tempDir, mfs)

	filePath := filepath.Join(tempDir, "guest_metadata.json")
	requireErr := os.WriteFile(filePath, []byte("{}"), 0o600)
	assert.NoError(t, requireErr)

	mfs.readError = errors.New("read error")
	err := store.Load()
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "read error")
}