-
Notifications
You must be signed in to change notification settings - Fork 12
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
liujianping
committed
May 23, 2019
1 parent
c184c41
commit 52da934
Showing
19 changed files
with
459 additions
and
104 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
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,28 @@ | ||
package build | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuild(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want string | ||
}{ | ||
{ | ||
"default", | ||
"dev, commit none, built at unknown", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := String(); got != tt.want { | ||
t.Errorf("String() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
Info("v0.0.1", "now", "timestamp") | ||
assert.Equal(t, "v0.0.1, commit now, built at timestamp", String()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOutput(t *testing.T) { | ||
outCmd := RootCmd() | ||
outCmd.Flags().Set("config", "../etc/job.yaml") | ||
outCmd.Flags().Set("output", "true") | ||
assert.Nil(t, Main(outCmd, []string{})) | ||
} | ||
|
||
func TestMain(t *testing.T) { | ||
ts := httptest.NewServer( | ||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.RequestURI { | ||
case "/get": | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
case "/post": | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
case "/json": | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
case "/text": | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
case "/xml": | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
case "/timeout": | ||
time.Sleep(5 * time.Second) | ||
w.WriteHeader(http.StatusOK) | ||
io.WriteString(w, `ok`) | ||
return | ||
default: | ||
http.NotFound(w, r) | ||
} | ||
}), | ||
) | ||
defer ts.Close() | ||
|
||
mainCmd := RootCmd() | ||
mainCmd.Flags().Set("config", "../etc/job.yaml") | ||
mainCmd.Flags().Set("report", "true") | ||
assert.Nil(t, Main(mainCmd, []string{})) | ||
} | ||
|
||
func TestVersion(t *testing.T) { | ||
verCmd := RootCmd() | ||
verCmd.Flags().Set("version", "true") | ||
assert.Nil(t, Main(verCmd, []string{})) | ||
} | ||
|
||
func TestReport(t *testing.T) { | ||
rptCmd := RootCmd() | ||
rptCmd.Flags().Set("report", "true") | ||
assert.Nil(t, Main(rptCmd, []string{"echo", "hello"})) | ||
} | ||
|
||
func TestVerbose(t *testing.T) { | ||
verbCmd := RootCmd() | ||
verbCmd.Flags().Set("verbose", "true") | ||
assert.Nil(t, Main(verbCmd, []string{"echox", "hello"})) | ||
} |
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
Oops, something went wrong.