-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edac0d0
commit f96f217
Showing
2 changed files
with
69 additions
and
1 deletion.
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,5 +1,7 @@ | ||
run: | ||
deadline: 1m | ||
timeout: 5m | ||
skip-files: | ||
- '(.+)_test\.go' | ||
|
||
linters: | ||
disable-all: false | ||
|
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,66 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestMain_ConnectionRefused(t *testing.T) { | ||
cmd := exec.Command("go", "run", "./...") | ||
out, _ := cmd.CombinedOutput() | ||
|
||
actual := string(out) | ||
expected := "UNKNOWN - url and token are required" | ||
|
||
if !strings.Contains(actual, expected) { | ||
t.Error("\nActual: ", actual, "\nExpected: ", expected) | ||
} | ||
} | ||
|
||
type IntegrationTest struct { | ||
name string | ||
server *httptest.Server | ||
args []string | ||
expected string | ||
} | ||
|
||
func TestMainCmd(t *testing.T) { | ||
tests := []IntegrationTest{ | ||
{ | ||
name: "invalid-json", | ||
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(`{"foo}`)) | ||
})), | ||
args: []string{"run", "./...", "-T", "test", "--url"}, | ||
expected: "UNKNOWN - could not decode JSON from body", | ||
}, | ||
{ | ||
name: "empty-response", | ||
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(`{"data" : [ {"id": "c86dc437", "name": "test1"}], "pagination": { "nextCursor": null, "totalItems": 2}}`)) | ||
})), | ||
args: []string{"run", "./...", "-T", "test", "--url"}, | ||
expected: "WARNING -", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
defer test.server.Close() | ||
|
||
cmd := exec.Command("go", append(test.args, test.server.URL)...) | ||
out, _ := cmd.CombinedOutput() | ||
|
||
actual := string(out) | ||
|
||
if !strings.Contains(actual, test.expected) { | ||
t.Error("\nActual: ", actual, "\nExpected: ", test.expected) | ||
} | ||
}) | ||
} | ||
} |