// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause

//go:build !ts_omit_netlog && !ts_omit_logtail

package netlog

import (
	"testing"

	"tailscale.com/logtail"
)

func TestNetworkLogUploadTarget(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name     string
		baseURL  string
		wantURL  string
		wantHost string
	}{
		{
			name:     "empty",
			baseURL:  "",
			wantURL:  "",
			wantHost: logtail.DefaultHost,
		},
		{
			name:     "invalid",
			baseURL:  "://bad",
			wantURL:  "",
			wantHost: logtail.DefaultHost,
		},
		{
			name:     "custom",
			baseURL:  "https://mirage.example.com/control/",
			wantURL:  "https://mirage.example.com/control",
			wantHost: "mirage.example.com",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotURL, gotHost := networkLogUploadTarget(tt.baseURL)
			if gotURL != tt.wantURL || gotHost != tt.wantHost {
				t.Fatalf("networkLogUploadTarget(%q) = (%q, %q), want (%q, %q)", tt.baseURL, gotURL, gotHost, tt.wantURL, tt.wantHost)
			}
		})
	}
}
