-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubmit_test.go
107 lines (95 loc) · 3.02 KB
/
submit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package p4
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestSubmit_SubmitShelve(t *testing.T) {
var (
err error
conn *Conn
)
conn, err = setup(t)
Convey("test Submit", t, func() {
So(err, ShouldBeNil)
Convey("Create partitioned client, reshelve, submit and delete client", func() {
owner := os.Getenv("P4USER")
var (
shelve uint64 = 8113
reshelveCL uint64
submitCL uint64
submitter = "tangyongqiang"
)
// 查询stream
stream, err := conn.ChangeListStream(shelve)
So(stream, ShouldNotBeEmpty)
So(err, ShouldBeNil)
// 创建临时partitioned workspace
streamWs := strings.Trim(stream, "/")
// root_DM99.ZGame.Project-Development-xiner_test
client := owner + "_" + strings.ReplaceAll(streamWs, "/", "-")
wsRoot, _ := os.Getwd()
clientInfo := Client{
Client: client,
Owner: owner,
Root: wsRoot + "/" + client,
Options: "noallwrite noclobber nocompress unlocked nomodtime normdir",
SubmitOptions: "submitunchanged",
Stream: stream,
View: []string{fmt.Sprintf("%s/... //%s/...", stream, client)},
}
message, err := conn.CreatePartitionClient(clientInfo)
So(message, ShouldNotBeEmpty)
// Client root_DM99.ZGame.Project-Development-xiner_test saved.
So(message, ShouldEqual, fmt.Sprintf("Client %s saved.", client))
So(err, ShouldBeNil)
// 将shelve CL给reshelve成新的shelve CL
conn = conn.SetClient(client)
message, err = conn.Reshelve(shelve)
So(message, ShouldNotBeEmpty)
So(err, ShouldBeNil)
regex := regexp.MustCompile("Change (\\d+) files shelved.")
fields := regex.FindStringSubmatch(message)
if len(fields) == 2 {
reshelveCL, _ = strconv.ParseUint(fields[1], 10, 64)
}
// 提交新的shelve CL
message, err = conn.SubmitShelve(reshelveCL)
So(message, ShouldNotBeEmpty)
if err != nil {
message, err = conn.DeleteShelve(reshelveCL)
So(message, ShouldNotBeEmpty)
So(err, ShouldBeNil)
} else {
// 提交成功,修改提交人
regex1 := regexp.MustCompile("renamed change (\\d+) and submitted.")
regex2 := regexp.MustCompile("Change (\\d+) submitted.")
fields = regex1.FindStringSubmatch(message)
if len(fields) == 2 {
submitCL, _ = strconv.ParseUint(fields[1], 10, 64)
} else {
fields = regex2.FindStringSubmatch(message)
if len(fields) == 2 {
submitCL, _ = strconv.ParseUint(fields[1], 10, 64)
}
}
cl, err := conn.ChangeList(submitCL)
So(err, ShouldBeNil)
cl.User = submitter
message, err = conn.UpdateChangeList(*cl)
So(message, ShouldEqual, fmt.Sprintf("Change %d updated.", submitCL))
So(err, ShouldBeNil)
}
// 删除临时partitioned workspace
message, err = conn.DeleteClient(client)
So(message, ShouldNotBeEmpty)
// Client root_DM99.ZGame.Project-Development-xiner_test deleted.
So(message, ShouldEqual, fmt.Sprintf("Client %s deleted.", client))
So(err, ShouldBeNil)
})
})
}