-
Notifications
You must be signed in to change notification settings - Fork 255
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
Showing
18 changed files
with
563 additions
and
6 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,65 @@ | ||
package curl | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_setData(t *testing.T) { | ||
t.Parallel() | ||
|
||
} | ||
|
||
func Test_setDataValue(t *testing.T) { | ||
t.Parallel() | ||
|
||
} | ||
|
||
func Test_compareExpectResult(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
expectCode int | ||
realCode int | ||
expectData string | ||
realData string | ||
expectResult bool | ||
expectErr error | ||
}{ | ||
{ | ||
expectCode: 200, | ||
realCode: 200, | ||
expectData: "ok", | ||
realData: "test is ok", | ||
expectResult: true, | ||
expectErr: nil, | ||
}, | ||
{ | ||
expectCode: 200, | ||
realCode: 500, | ||
expectData: "ok", | ||
realData: "test is ok", | ||
expectResult: false, | ||
expectErr: fmt.Errorf("return status code is: 500, expect: 200"), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
ok, err := compareExpectResult(test.expectCode, test.realCode, test.expectData, test.realData) | ||
assert.EqualValues(t, test.expectErr, err) | ||
assert.EqualValues(t, test.expectResult, ok) | ||
} | ||
} | ||
|
||
func Test_joinIdx(t *testing.T) { | ||
t.Parallel() | ||
httpData, httpTimeCost, httpTarget, httpStatusCode, httpRespHead, httpErrState, httpErrMsg := joinIdx("1") | ||
assert.EqualValues(t, HttpData+"_1", httpData) | ||
assert.EqualValues(t, HttpTimeCost+"_1", httpTimeCost) | ||
assert.EqualValues(t, HttpTarget+"_1", httpTarget) | ||
assert.EqualValues(t, HttpStatusCode+"_1", httpStatusCode) | ||
assert.EqualValues(t, HttpRespHead+"_1", httpRespHead) | ||
assert.EqualValues(t, HttpErrState+"_1", httpErrState) | ||
assert.EqualValues(t, HttpErrMsg+"_1", httpErrMsg) | ||
} |
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,41 @@ | ||
// +build !windows | ||
|
||
package system | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/shirou/gopsutil/cpu" | ||
) | ||
|
||
func Test_totalCpuTime(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
timeStats cpu.TimesStat | ||
expect float64 | ||
}{ | ||
{ | ||
timeStats: cpu.TimesStat{}, | ||
expect: 0, | ||
}, | ||
{ | ||
timeStats: cpu.TimesStat{ | ||
User: 1, | ||
System: 1, | ||
Idle: 1, | ||
Nice: 1, | ||
Iowait: 1, | ||
Irq: 1, | ||
Softirq: 1, | ||
Steal: 1, | ||
}, | ||
expect: 8, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
assert.EqualValues(t, test.expect, totalCpuTime(test.timeStats)) | ||
} | ||
} |
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,59 @@ | ||
// +build windows | ||
|
||
package system | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_isTotalCpuTimeStat(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
expect bool | ||
}{ | ||
{ | ||
name: "", | ||
expect: false, | ||
}, | ||
{ | ||
name: WindowsCPUTotalKey, | ||
expect: false, | ||
}, | ||
{ | ||
name: MetricCPUTotalKey, | ||
expect: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
assert.EqualValues(t, test.expect, isTotalCpuTimeStat(test.name)) | ||
} | ||
} | ||
|
||
func Test_isTotalCpuUsageStat(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
expect bool | ||
}{ | ||
{ | ||
name: "", | ||
expect: false, | ||
}, | ||
{ | ||
name: WindowsCPUTotalKey, | ||
expect: true, | ||
}, | ||
{ | ||
name: MetricCPUTotalKey, | ||
expect: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
assert.EqualValues(t, test.expect, isTotalCpuUsageStat(test.name)) | ||
} | ||
} |
File renamed without changes.
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,39 @@ | ||
package system | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_readProcFile(t *testing.T) { | ||
t.Parallel() | ||
data, err := readProcFile("Test_readProcFile") | ||
assert.Nil(t, data) | ||
assert.Nil(t, err) | ||
|
||
err = createFile("./Test_readProcFile", "Test_readProcFile") | ||
defer os.RemoveAll("./Test_readProcFile") | ||
assert.Nil(t, err) | ||
|
||
data, err = readProcFile("Test_readProcFile") | ||
assert.EqualValues(t, []byte("Test_readProcFile"), data) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func Test_execPS(t *testing.T) { | ||
t.Parallel() | ||
data, err := execPS() | ||
assert.Nil(t, err) | ||
assert.NotNil(t, data) | ||
} | ||
|
||
func createFile(filename, content string) error { | ||
if err := ioutil.WriteFile(filename, []byte(content), 0755); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.