diff --git a/client.go b/client.go index 054e045..233bfdc 100644 --- a/client.go +++ b/client.go @@ -61,10 +61,6 @@ type Client struct { } func NewWithGrafanaURL(base_url, token, grafana_url string) (*Client, error) { - if token == "" { - return nil, fmt.Errorf("Token required") - } - if base_url == "" { return nil, fmt.Errorf("BaseUrl required") } @@ -77,10 +73,6 @@ func NewWithGrafanaURL(base_url, token, grafana_url string) (*Client, error) { } func New(base_url, token string) (*Client, error) { - if token == "" { - return nil, fmt.Errorf("Token required") - } - if base_url == "" { return nil, fmt.Errorf("BaseUrl required") } diff --git a/client_test.go b/client_test.go index 5efd0c6..a7c202c 100644 --- a/client_test.go +++ b/client_test.go @@ -47,6 +47,19 @@ func TestNewClient(t *testing.T) { } } +func TestNewClientEmptyToken(t *testing.T) { + c, err := New("base_url", "") + if err != nil { + t.Fatalf("Failed to create client: %v", err) + } + + expectedBaseURL := "base_url/" + apiVersionPath + + if c.BaseURL().String() != expectedBaseURL { + t.Errorf("NewClient BaseURL is %s, want %s", c.BaseURL().String(), expectedBaseURL) + } +} + func TestNewClientWithGrafanaURL(t *testing.T) { c, err := NewWithGrafanaURL("base_url", "token", "grafana_url") if err != nil { @@ -64,6 +77,23 @@ func TestNewClientWithGrafanaURL(t *testing.T) { } } +func TestNewClientWithGrafanaURLEmptyToken(t *testing.T) { + c, err := NewWithGrafanaURL("base_url", "", "grafana_url") + if err != nil { + t.Fatalf("Failed to create client: %v", err) + } + + expectedBaseURL := "base_url/" + apiVersionPath + + if c.BaseURL().String() != expectedBaseURL { + t.Errorf("NewClient BaseURL is %s, want %s", c.BaseURL().String(), expectedBaseURL) + } + + if c.GrafanaURL().String() != "grafana_url" { + t.Errorf("NewClient GrafanaURL is %s, want grafana_url", c.GrafanaURL().String()) + } +} + func TestCheckRequest(t *testing.T) { c, err := New("base_url", "token") if err != nil {