Revision 3c81218ba373248450e46728f5667a899bb38109 authored by Grot (@grafanabot) on 14 May 2021, 06:52:03 UTC, committed by GitHub on 14 May 2021, 06:52:03 UTC
* Timeline: Text align option, but does not work

* working text alignment

* Refactoring and fixing rendering text values on the right edge that does not fit

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
(cherry picked from commit 96183d70a8bebdd6ee79a01fcc3611a8fb3b9da1)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
1 parent 728a2bd
Raw File
url_test.go
package util

import (
	"net/url"
	"testing"

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

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

	tests := []struct {
		description string
		base        string
		path        string
		expected    string
	}{
		{
			description: "RHS is empty",
			base:        "http://localhost:8080",
			path:        "",
			expected:    "http://localhost:8080",
		},
		{
			description: "RHS is empty and LHS has trailing slash",
			base:        "http://localhost:8080/",
			path:        "",
			expected:    "http://localhost:8080/",
		},
		{
			description: "neither has trailing slash",
			base:        "http://localhost:8080",
			path:        "api",
			expected:    "http://localhost:8080/api",
		},
		{
			description: "LHS has trailing slash",
			base:        "http://localhost:8080/",
			path:        "api",
			expected:    "http://localhost:8080/api",
		},
		{
			description: "LHS and RHS has trailing slash",
			base:        "http://localhost:8080/",
			path:        "api/",
			expected:    "http://localhost:8080/api/",
		},
		{
			description: "LHS has trailing slash and RHS has preceding slash",
			base:        "http://localhost:8080/",
			path:        "/api/",
			expected:    "http://localhost:8080/api/",
		},
	}
	for _, testcase := range tests {
		t.Run("where "+testcase.description, func(t *testing.T) {
			assert.Equalf(
				t,
				testcase.expected,
				JoinURLFragments(testcase.base, testcase.path),
				"base: '%s', path: '%s'",
				testcase.base,
				testcase.path,
			)
		})
	}
}

func TestNewURLQueryReader(t *testing.T) {
	u, err := url.Parse("http://www.abc.com/foo?bar=baz&bar2=baz2")
	require.NoError(t, err)

	uqr, err := NewURLQueryReader(u)
	require.NoError(t, err)

	assert.Equal(t, "baz", uqr.Get("bar", "foodef"), "first param")
	assert.Equal(t, "baz2", uqr.Get("bar2", "foodef"), "second param")
	assert.Equal(t, "foodef", uqr.Get("bar3", "foodef"), "non-existing param, use fallback")
}
back to top