From 874e35b91659601ec96fb257264a3b25b9cbcedb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 30 Dec 2025 10:49:28 -0500 Subject: [PATCH] Write a test for config validation --- cmd/mailbox-shuffler/config_test.go | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 cmd/mailbox-shuffler/config_test.go diff --git a/cmd/mailbox-shuffler/config_test.go b/cmd/mailbox-shuffler/config_test.go new file mode 100644 index 0000000..871449e --- /dev/null +++ b/cmd/mailbox-shuffler/config_test.go @@ -0,0 +1,104 @@ +// mailpopbox +// Copyright 2025 Blue Static +// This program is free software licensed under the GNU General Public License, +// version 3.0. The full text of the license can be found in LICENSE.txt. +// SPDX-License-Identifier: GPL-3.0-only + +package main + +import ( + "testing" +) + +func TestInvalidConfigs(t *testing.T) { + configs := []Config{ + // Missing Email. + { + Monitor: []MonitorConfig{{ + PollIntervalSeconds: 10, + Source: ServerConfig{ + Type: ServerTypePOP3, + ServerAddr: "localhost:995", + }, + Destination: ServerConfig{ + Type: ServerTypeGmail, + Email: "here", + }, + }}, + }, + { + Monitor: []MonitorConfig{{ + PollIntervalSeconds: 10, + Source: ServerConfig{ + Type: ServerTypePOP3, + Email: "here", + ServerAddr: "localhost:995", + }, + Destination: ServerConfig{Type: ServerTypeGmail}, + }}, + }, + // Missing PollIntervalSeconds. + { + Monitor: []MonitorConfig{{ + Source: ServerConfig{ + Type: ServerTypePOP3, + Email: "here", + ServerAddr: "localhost:995", + }, + Destination: ServerConfig{ + Type: ServerTypeGmail, + Email: "here", + }, + }}, + }, + // Missing ServerAddr. + { + Monitor: []MonitorConfig{{ + PollIntervalSeconds: 10, + Source: ServerConfig{ + Type: ServerTypePOP3, + Email: "here", + }, + Destination: ServerConfig{ + Type: ServerTypeGmail, + Email: "here", + }, + }}, + }, + // Invalid server types. + { + Monitor: []MonitorConfig{{ + PollIntervalSeconds: 10, + Source: ServerConfig{ + Type: ServerType("pop5"), + Email: "here", + ServerAddr: "localhost:995", + }, + Destination: ServerConfig{ + Type: ServerTypeGmail, + Email: "here", + }, + }}, + }, + { + Monitor: []MonitorConfig{{ + PollIntervalSeconds: 10, + Source: ServerConfig{ + Type: ServerTypePOP3, + Email: "here", + ServerAddr: "localhost:995", + }, + Destination: ServerConfig{ + Type: ServerType("google-inbox-rip"), + Email: "here", + }, + }}, + }, + } + for i, cfg := range configs { + err := cfg.Validate() + if err == nil { + t.Errorf("Expected error for config #%d: %#v", i, cfg) + } + } +} -- 2.43.5