-
Notifications
You must be signed in to change notification settings - Fork 77
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
add testcase #144
Merged
Merged
add testcase #144
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#/bin/bash | ||
mkdir -p ~/.paddle | ||
cat > ~/.paddle/config << EOF | ||
datacenters: | ||
- name: datacenter1 | ||
username: [email protected] | ||
password: T123 | ||
endpoint: http://127.0.0.1:8080 | ||
current-datacenter: datacenter1 | ||
EOF |
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,62 @@ | ||
package pfsmodules | ||
|
||
import ( | ||
"crypto/md5" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestGetDiffMeta(t *testing.T) { | ||
var src []ChunkMeta | ||
var dst []ChunkMeta | ||
|
||
var data []ChunkMeta | ||
|
||
for i := 0; i < 4; i++ { | ||
data = append(data, ChunkMeta{ | ||
Offset: int64(i), | ||
Checksum: fmt.Sprintf("%x", md5.Sum([]byte("1"))), | ||
Len: 1}) | ||
} | ||
|
||
src = data[0:3] | ||
// check when len(dst) is 0 | ||
diff, _ := GetDiffChunkMeta(src, dst) | ||
if len(diff) != 3 { | ||
t.Error(len(diff)) | ||
} | ||
|
||
for i, _ := range diff { | ||
if diff[i] != src[i] { | ||
t.Error(i) | ||
} | ||
} | ||
|
||
// check when dst is same as src | ||
dst = src | ||
diff, _ = GetDiffChunkMeta(src, dst) | ||
if len(diff) != 0 { | ||
t.Error(len(diff)) | ||
} | ||
|
||
// check when dst is small than src | ||
dst = dst[:0] | ||
dst = append(dst, data[0]) | ||
dst = append(dst, data[2]) | ||
|
||
diff, _ = GetDiffChunkMeta(src, dst) | ||
if len(diff) != 1 { | ||
t.Error(len(diff)) | ||
} | ||
|
||
if diff[0] != data[1] { | ||
t.Error(0) | ||
} | ||
|
||
// check when dst is large then src | ||
dst = data | ||
diff, _ = GetDiffChunkMeta(src, dst) | ||
if len(diff) != 0 { | ||
t.Error(len(diff)) | ||
} | ||
} |
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,47 @@ | ||
package pfsmodules | ||
|
||
import ( | ||
"flag" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestNewCpCmdFromFlag(t *testing.T) { | ||
cmdLine := "cp -v /pfs/datacenter/home/user1/1.txt /pfs/datacenter/home/user1/2.txt ./user1/" | ||
a := strings.Split(cmdLine, " ") | ||
|
||
flag := flag.NewFlagSet("cp", flag.ExitOnError) | ||
flag.Bool("v", false, "") | ||
|
||
if err := flag.Parse(a[1:]); err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
d, err := newCpCmdFromFlag(flag) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
if d.Method != "cp" { | ||
t.Error(d.Method) | ||
} | ||
|
||
if !d.V { | ||
t.Error(d.V) | ||
} | ||
|
||
if d.Dst != "./user1/" { | ||
t.Error(d.Dst) | ||
} | ||
|
||
if len(d.Src) != 2 { | ||
t.Error(len(d.Src)) | ||
} | ||
|
||
for _, s := range d.Src { | ||
if s != "/pfs/datacenter/home/user1/1.txt" && | ||
s != "/pfs/datacenter/home/user1/2.txt" { | ||
t.Error(s) | ||
} | ||
} | ||
} |
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,73 @@ | ||
package pfsmodules | ||
|
||
import ( | ||
"flag" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestNewLsCmdFromURLParam(t *testing.T) { | ||
s := LsCmd{ | ||
Method: "ls", | ||
R: false, | ||
Args: []string{"/pfs/test1/", "/pfs/test2/"}, | ||
} | ||
|
||
path := "arg=%2Fpfs%2Ftest1%2F&arg=%2Fpfs%2Ftest2%2F&method=ls&r=false" | ||
|
||
d, err := NewLsCmdFromURLParam(path) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
if s.Method != d.Method { | ||
t.Error(d.Method) | ||
} | ||
|
||
if s.R != d.R { | ||
t.Error(d.R) | ||
} | ||
|
||
eq := reflect.DeepEqual(s.Args, d.Args) | ||
if !eq { | ||
t.Error(s.Args) | ||
t.Error(d.Args) | ||
} | ||
} | ||
|
||
func TestNewLsCmdFromFlag(t *testing.T) { | ||
cmdLine := "ls -r /pfs/datacenter/home/user1/1.txt /pfs/datacenter/home/user1/" | ||
a := strings.Split(cmdLine, " ") | ||
|
||
flag := flag.NewFlagSet("ls", flag.ExitOnError) | ||
flag.Bool("r", false, "") | ||
|
||
if err := flag.Parse(a[1:]); err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
d, err := newLsCmdFromFlag(flag) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
if d.Method != "ls" { | ||
t.Error(d.Method) | ||
} | ||
|
||
if !d.R { | ||
t.Error(d.R) | ||
} | ||
|
||
if len(d.Args) != 2 { | ||
t.Error(len(d.Args)) | ||
} | ||
|
||
for _, s := range d.Args { | ||
if s != "/pfs/datacenter/home/user1/1.txt" && | ||
s != "/pfs/datacenter/home/user1/" { | ||
t.Error(s) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of generating this file with a script (unit test breaks without running this script), you can check in this file into the code base, maybe under
testdata
, like:https://github.com/golang/go/blob/master/src/net/testdata/hosts . And add argument to override the default location~/.paddle
to the test file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config
是一个全局变量,这个参数不太好覆盖。如果不用这个全局变量,需要改动的地方太多。这个能否后续再想想如何更简单的解决这问题?