Skip to content

Commit 6279545

Browse files
committed
Added assertion
1 parent 8c19bdd commit 6279545

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

steps/sampletest/context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func NewSampleTestFeatureContext(fc *featurecontext.FeatureContext, sc *godog.Sc
1818

1919
func (f *SampleTestFeatureContext) Register(ctx *godog.ScenarioContext) {
2020
// steps
21-
ctx.Step(`^user "([^"]*)" shares a file "([^"]*)" with the following users concurrently$`, f.userSharesAFileWithTheFollowingUsers)
21+
ctx.Step(`^user "([^"]*)" shares a file "([^"]*)" with the following users concurrently$`, f.UserSharesAFileWithTheFollowingUsers)
22+
ctx.Step(`^the concurrent user sharing should have been successfull$`, f.TheConcurrentUserSharingShouldHaveBeenSuccessfull)
2223
}

steps/sampletest/steps.go

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sampletest
22

33
import (
4+
"errors"
45
"fmt"
56
identityv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
67
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
@@ -14,13 +15,15 @@ import (
1415
)
1516

1617
type CreateShareResult struct {
17-
ShareInfo *identityv1beta1.UserId // Replace with your actual type
18-
Result *collaborationv1beta1.CreateShareResponse // Replace with the actual response type
18+
ResourceInformation *providerv1beta1.ResourceInfo
19+
InformationOfSharee *identityv1beta1.UserId
1920
Status *rpc.Status
20-
Err error
21+
Error error
2122
}
2223

23-
func (f *SampleTestFeatureContext) userSharesAFileWithTheFollowingUsers(shareer string, resourceName string, sharees *godog.Table) error {
24+
var concurentResults []*CreateShareResult
25+
26+
func (f *SampleTestFeatureContext) UserSharesAFileWithTheFollowingUsers(shareer string, resourceName string, sharees *godog.Table) error {
2427
ctx, err := f.GetAuthContext(shareer)
2528
if err != nil {
2629
return err
@@ -104,7 +107,6 @@ func (f *SampleTestFeatureContext) userSharesAFileWithTheFollowingUsers(shareer
104107

105108
for _, UserId := range collectedShareesInfos {
106109
wg.Add(1)
107-
108110
go func(UserId *identityv1beta1.UserId) {
109111
defer wg.Done()
110112
createShareResponse, err := f.Client.CreateShare(
@@ -126,29 +128,37 @@ func (f *SampleTestFeatureContext) userSharesAFileWithTheFollowingUsers(shareer
126128
)
127129

128130
result := CreateShareResult{
129-
ShareInfo: UserId,
130-
Result: createShareResponse,
131-
Err: err,
132-
}
133-
134-
if err == nil && createShareResponse != nil {
135-
result.Status = createShareResponse.GetStatus()
131+
ResourceInformation: resourceInfo,
132+
InformationOfSharee: UserId,
133+
Status: createShareResponse.GetStatus(),
134+
Error: err,
136135
}
137136
resultChannel <- result
138137

139138
}(UserId)
140139
}
141-
142140
wg.Wait()
143141
close(resultChannel)
144142

145143
for result := range resultChannel {
146-
if result.Err != nil {
147-
fmt.Printf("Error for ShareInformation: %+v - %v\n", result.ShareInfo, result.Err)
148-
} else {
149-
fmt.Printf("Success for ShareInfo: %+v - Status: %s\n", result.ShareInfo, result.Status)
150-
}
144+
concurentResults = append(concurentResults, &CreateShareResult{
145+
ResourceInformation: result.ResourceInformation,
146+
InformationOfSharee: result.InformationOfSharee,
147+
Status: result.Status,
148+
Error: result.Error,
149+
})
151150
}
152151

153152
return nil
154153
}
154+
155+
func (f *SampleTestFeatureContext) TheConcurrentUserSharingShouldHaveBeenSuccessfull( ) error {
156+
for _, concurentResult := range concurentResults {
157+
if concurentResult.Status.Code != rpc.Code_CODE_OK || concurentResult.Error != nil {
158+
err := errors.New("Could not create share for user with information " + concurentResult.InformationOfSharee.String() + " for the resource " + concurentResult.ResourceInformation.Name)
159+
fmt.Println(err)
160+
}
161+
}
162+
return nil
163+
}
164+

0 commit comments

Comments
 (0)