-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check type assertions and added GetStatusCode (#122)
* Check type assertions and added GetStatusCode * Use `GetStatusCode` in stream dashboard
- Loading branch information
1 parent
387c18e
commit e98e687
Showing
19 changed files
with
201 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.70.13 | ||
1.70.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_DeleteDestionation_when_connection_is_closed(t *testing.T) { | ||
var server *httptest.Server | ||
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, "/public/v0.2/blars/projects/tacoman/destinations/hi", r.URL.Path) | ||
|
||
server.CloseClientConnections() | ||
})) | ||
defer server.Close() | ||
|
||
t.Setenv("LIGHTSTEP_API_BASE_URL", server.URL) | ||
c := NewClient("api", "blars", "staging") | ||
err := c.DeleteDestination(context.Background(), "tacoman", "hi") | ||
|
||
assert.NotNil(t, err) | ||
|
||
apiErr, ok := err.(APIClientError) | ||
|
||
assert.True(t, ok) | ||
assert.Equal(t, -1, apiErr.GetStatusCode()) | ||
} | ||
|
||
func Test_DeleteDestination_when_connection_has_wrong_content_length(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Length", "1") // set content length to 1 so reading body fails | ||
})) | ||
defer server.Close() | ||
|
||
t.Setenv("LIGHTSTEP_API_BASE_URL", server.URL) | ||
c := NewClient("api", "blars", "staging") | ||
err := c.DeleteDestination(context.Background(), "tacoman", "hi") | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "unexpected EOF", err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_DeleteMetricCondition_when_connection_is_closed(t *testing.T) { | ||
var server *httptest.Server | ||
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, "/public/v0.2/blars/projects/tacoman/metric_alerts/hi", r.URL.Path) | ||
|
||
server.CloseClientConnections() | ||
})) | ||
defer server.Close() | ||
|
||
t.Setenv("LIGHTSTEP_API_BASE_URL", server.URL) | ||
c := NewClient("api", "blars", "staging") | ||
err := c.DeleteMetricCondition(context.Background(), "tacoman", "hi") | ||
|
||
assert.NotNil(t, err) | ||
|
||
apiErr, ok := err.(APIClientError) | ||
|
||
assert.True(t, ok) | ||
assert.Equal(t, -1, apiErr.GetStatusCode()) | ||
} | ||
|
||
func Test_DeleteMetricCondition_when_connection_has_wrong_content_length(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Length", "1") // set content length to 1 so reading body fails | ||
})) | ||
defer server.Close() | ||
|
||
t.Setenv("LIGHTSTEP_API_BASE_URL", server.URL) | ||
c := NewClient("api", "blars", "staging") | ||
err := c.DeleteMetricCondition(context.Background(), "tacoman", "hi") | ||
|
||
assert.NotNil(t, err) | ||
assert.Equal(t, "unexpected EOF", err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters