package cmd

import (
	"testing"

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

func TestValidateBaseURL(t *testing.T) {
	tests := []struct {
		name        string
		input       string
		expectError bool
	}{
		{
			name:        "valid URL",
			input:       "https://hub.edge.de",
			expectError: false,
		},
		{
			name:        "valid URL with slash",
			input:       "https://hub.edge.de/",
			expectError: false,
		},

		{
			name:        "no schema",
			input:       "hub.edge.de",
			expectError: true,
		},

		{
			name:        "user set",
			input:       "https://user@hub.edge.de",
			expectError: true,
		},
		{
			name:        "user and password set",
			input:       "https://user:password@hub.edge.de/",
			expectError: true,
		},

		{
			name:        "contains path and query",
			input:       "http://hub.edge.de/index.html?a=b",
			expectError: true,
		},
		{
			name:        "contains query",
			input:       "http://hub.edge.de/?a=b",
			expectError: true,
		},

		{
			name:        "contains path and fragment",
			input:       "http://hub.edge.de/index.html#abc",
			expectError: true,
		},
		{
			name:        "contains fragment",
			input:       "http://hub.edge.de/#abc",
			expectError: true,
		},

		{
			name:        "contains path, query and fragment",
			input:       "http://hub.edge.de/index.html?a=b#abc",
			expectError: true,
		},
		{
			name:        "contains query and fragment",
			input:       "http://hub.edge.de/?a=b#abc",
			expectError: true,
		},

		{
			name:        "contains path, fragment and query",
			input:       "http://hub.edge.de/index.html#abc?a=b",
			expectError: true,
		},
		{
			name:        "contains fragment and query",
			input:       "http://hub.edge.de/#abc?a=b",
			expectError: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := validateBaseURL(tt.input)

			// Verify results
			if tt.expectError {
				assert.Error(t, err)
			} else {
				assert.NoError(t, err)
			}
		})
	}
}
