package cmd

import (
	"testing"
)

func TestCheckIPorHostnameAndPort(t *testing.T) {
	// Test cases for valid IP addresses or hostnames with ports
	validCases := []string{
		"127.0.0.1:8080",
		"localhost:8080",
		"example.com:8080",
		"[::1]:8080",
		"[2001:db8::1]:1234",
		"256.256.256.900:1234", // Looks weird, but is valid as a hostname.
	}

	for _, addr := range validCases {
		err := checkIPorHostnameAndPort(addr)
		if err != nil {
			t.Errorf("Expected no error for address %s, but got: %v", addr, err)
		}
	}
}

func TestCheckIPorHostnameAndPortInvalid(t *testing.T) {
	// Test cases for invalid IP addresses or hostnames with ports
	invalidCases := []string{
		":8080",       // Missing IP address or hostname
		"example.com", // Missing port
	}

	for _, addr := range invalidCases {
		err := checkIPorHostnameAndPort(addr)
		if err == nil {
			t.Errorf("Expected error for address %s, but got no error", addr)
		}
	}
}