Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package config

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

func TestDefaultConfig(t *testing.T) {
cfg := defaultConfig()
if cfg.Instance.Name != "microcks" {
t.Errorf("Expected default name 'microcks', got %s", cfg.Instance.Name)
}
if cfg.Instance.Driver != "docker" {
t.Errorf("Expected default driver 'docker', got %s", cfg.Instance.Driver)
}
}

func TestSaveAndLoadConfig(t *testing.T) {
tmpDir := t.TempDir()
cfgPath := filepath.Join(tmpDir, "test-config.yaml")

original := defaultConfig()
original.Instance.Image = "test-image"

err := SaveConfig(cfgPath, original)
if err != nil {
t.Fatalf("SaveConfig failed: %v", err)
}

loaded, err := LoadConfig(cfgPath)
if err != nil {
t.Fatalf("LoadConfig failed: %v", err)
}

if loaded.Instance.Image != "test-image" {
t.Errorf("Expected image 'test-image', got %s", loaded.Instance.Image)
}
}

func TestEnsureConfigCreatesFile(t *testing.T) {
tmpDir := t.TempDir()
cfgPath := filepath.Join(tmpDir, "new-config.yaml")

cfg, err := EnsureConfig(cfgPath)
if err != nil {
t.Fatalf("EnsureConfig failed: %v", err)
}

if cfg.Instance.Name != "microcks" {
t.Errorf("Expected default name 'microcks', got %s", cfg.Instance.Name)
}

if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
t.Errorf("Config file was not created at %s", cfgPath)
}
}