Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow instantiating the client with an empty string token #27

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
30 changes: 30 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down