From 254db32eed420a1b416c0567ccd23d2b7b5d7408 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 6 Jul 2025 10:47:29 +0000 Subject: [PATCH] make fmt --- src/main.go | 2 +- src/main_test.go | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main.go b/src/main.go index d40d846..3e46ddd 100644 --- a/src/main.go +++ b/src/main.go @@ -327,4 +327,4 @@ func main() { if err := rootCmd.Execute(); err != nil { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/src/main_test.go b/src/main_test.go index 5e8b3dd..2b5f864 100644 --- a/src/main_test.go +++ b/src/main_test.go @@ -8,7 +8,7 @@ import ( func TestNewRouterBackup(t *testing.T) { rb := NewRouterBackup("test-host", "test-user", "test-pass", "/test/key", 2222) - + if rb.hostname != "test-host" { t.Errorf("Expected hostname 'test-host', got '%s'", rb.hostname) } @@ -56,7 +56,7 @@ func TestFindDefaultSSHKey(t *testing.T) { func TestFindDefaultSSHKeyNotFound(t *testing.T) { // Create a temporary directory with no SSH keys tempDir := t.TempDir() - + // Temporarily change HOME environment variable originalHome := os.Getenv("HOME") defer os.Setenv("HOME", originalHome) @@ -72,7 +72,7 @@ func TestLoadConfig(t *testing.T) { // Create a temporary config file tempDir := t.TempDir() configPath := filepath.Join(tempDir, "test-config.yaml") - + configContent := `types: test-type: commands: @@ -88,7 +88,7 @@ devices: commands: - direct command ` - + err := os.WriteFile(configPath, []byte(configContent), 0644) if err != nil { t.Fatalf("Failed to create test config file: %v", err) @@ -103,12 +103,12 @@ devices: if len(config.Types) != 1 { t.Errorf("Expected 1 type, got %d", len(config.Types)) } - + testType, exists := config.Types["test-type"] if !exists { t.Error("Expected 'test-type' to exist in types") } - + if len(testType.Commands) != 2 { t.Errorf("Expected 2 commands in test-type, got %d", len(testType.Commands)) } @@ -117,16 +117,16 @@ devices: if len(config.Devices) != 2 { t.Errorf("Expected 2 devices, got %d", len(config.Devices)) } - + testDevice, exists := config.Devices["test-device"] if !exists { t.Error("Expected 'test-device' to exist in devices") } - + if testDevice.User != "testuser" { t.Errorf("Expected user 'testuser', got '%s'", testDevice.User) } - + if testDevice.Type != "test-type" { t.Errorf("Expected type 'test-type', got '%s'", testDevice.Type) } @@ -142,7 +142,7 @@ func TestLoadConfigInvalidFile(t *testing.T) { func TestLoadConfigInvalidYAML(t *testing.T) { tempDir := t.TempDir() configPath := filepath.Join(tempDir, "invalid-config.yaml") - + // Create invalid YAML content invalidYAML := `types: test-type: @@ -150,7 +150,7 @@ func TestLoadConfigInvalidYAML(t *testing.T) { - show version invalid: [unclosed ` - + err := os.WriteFile(configPath, []byte(invalidYAML), 0644) if err != nil { t.Fatalf("Failed to create invalid config file: %v", err) @@ -164,16 +164,16 @@ func TestLoadConfigInvalidYAML(t *testing.T) { func TestBackupCommandsDirectoryCreation(t *testing.T) { rb := NewRouterBackup("test-host", "test-user", "", "", 22) - + tempDir := t.TempDir() outputDir := filepath.Join(tempDir, "new-directory") - + // Test with empty commands to avoid SSH connection err := rb.BackupCommands([]string{}, outputDir) if err != nil { t.Fatalf("BackupCommands failed: %v", err) } - + // Check if directory was created if _, err := os.Stat(outputDir); os.IsNotExist(err) { t.Error("Expected output directory to be created") @@ -182,16 +182,16 @@ func TestBackupCommandsDirectoryCreation(t *testing.T) { func TestBackupCommandsFileCreation(t *testing.T) { rb := NewRouterBackup("test-host", "test-user", "", "", 22) - + tempDir := t.TempDir() expectedFilePath := filepath.Join(tempDir, "test-host") - + // Test with empty commands to avoid SSH connection err := rb.BackupCommands([]string{}, tempDir) if err != nil { t.Fatalf("BackupCommands failed: %v", err) } - + // Check if file was created if _, err := os.Stat(expectedFilePath); os.IsNotExist(err) { t.Error("Expected output file to be created") @@ -209,7 +209,7 @@ func BenchmarkLoadConfig(b *testing.B) { // Create a temporary config file tempDir := b.TempDir() configPath := filepath.Join(tempDir, "bench-config.yaml") - + configContent := `types: srlinux: commands: @@ -224,7 +224,7 @@ devices: user: user2 type: srlinux ` - + err := os.WriteFile(configPath, []byte(configContent), 0644) if err != nil { b.Fatalf("Failed to create benchmark config file: %v", err) @@ -264,7 +264,7 @@ func TestRouterBackupCreation(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { rb := NewRouterBackup(tt.hostname, tt.username, tt.password, tt.keyFile, tt.port) - + if rb.hostname != tt.hostname { t.Errorf("Expected hostname '%s', got '%s'", tt.hostname, rb.hostname) } @@ -282,4 +282,4 @@ func TestRouterBackupCreation(t *testing.T) { } }) } -} \ No newline at end of file +}