package main

import (
	"testing"

	"kra/internal/conf"
)

func TestSwaggerAddress(t *testing.T) {
	tests := []struct {
		name   string
		server *conf.Server
		admin  *conf.AdminBackend
		want   string
	}{
		{name: "default", want: "http://127.0.0.1:8000/swagger/index.html"},
		{name: "wildcard with prefix", server: &conf.Server{Http: &conf.Server_HTTP{Addr: "0.0.0.0:9000"}}, admin: &conf.AdminBackend{RouterPrefix: "/admin/"}, want: "http://127.0.0.1:9000/admin/swagger/index.html"},
		{name: "host", server: &conf.Server{Http: &conf.Server_HTTP{Addr: "example.test:8080"}}, want: "http://example.test:8080/swagger/index.html"},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			if got := swaggerAddress(test.server, test.admin); got != test.want {
				t.Fatalf("swaggerAddress() = %q, want %q", got, test.want)
			}
		})
	}
}
