-
Notifications
You must be signed in to change notification settings - Fork 9
/
submitresult_test.go
143 lines (140 loc) · 4.41 KB
/
submitresult_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"errors"
"reflect"
"testing"
"github.com/bitrise-io/bitrise-init/errormapper"
"github.com/bitrise-io/bitrise-init/models"
"github.com/bitrise-io/go-steputils/step"
)
func Test_resultClient_buildErrorScanResultModel(t *testing.T) {
type args struct {
stepID string
err error
}
tests := []struct {
name string
args args
want models.ScanResultModel
}{
{
name: "buildErrorScanResultModel (standard error)",
args: args{
stepID: "git-clone",
err: errors.New("standar error"),
},
want: models.ScanResultModel{
ScannerToErrorsWithRecommendations: map[string]models.ErrorsWithRecommendations{
"general": {
models.ErrorWithRecommendations{
Error: "Error in step git-clone: standar error",
Recommendations: step.Recommendation{
"DetailedError": errormapper.DetailedError{
Title: "standar error",
Description: "For more information, please see the log.",
},
},
},
},
},
},
},
{
name: "buildErrorScanResultModel (with step.Error without recommendations)",
args: args{
stepID: "git-clone",
err: step.NewError(
"git-clone",
"tag",
errors.New("step error without recommendations"),
"shortMsg: step error without recommendations"),
},
want: models.ScanResultModel{
ScannerToErrorsWithRecommendations: map[string]models.ErrorsWithRecommendations{
"general": {
models.ErrorWithRecommendations{
Error: "Error in step git-clone: step error without recommendations",
Recommendations: step.Recommendation{
"DetailedError": errormapper.DetailedError{
Title: "step error without recommendations",
Description: "For more information, please see the log.",
},
},
},
},
},
},
},
{
name: "buildErrorScanResultModel (with step.Error with recommendations without DetailedError)",
args: args{
stepID: "git-clone",
err: step.NewErrorWithRecommendations(
"git-clone",
"tag",
errors.New("with step.Error with recommendations without DetailedError"),
"shortMsg: with step.Error with recommendations without DetailedError",
step.Recommendation{
"BranchRecommendation": []string{"master", "feature1"},
}),
},
want: models.ScanResultModel{
ScannerToErrorsWithRecommendations: map[string]models.ErrorsWithRecommendations{
"general": {
models.ErrorWithRecommendations{
Error: "Error in step git-clone: with step.Error with recommendations without DetailedError",
Recommendations: step.Recommendation{
"BranchRecommendation": []string{"master", "feature1"},
"DetailedError": errormapper.DetailedError{
Title: "with step.Error with recommendations without DetailedError",
Description: "For more information, please see the log.",
},
},
},
},
},
},
},
{
name: "buildErrorScanResultModel (with step.Error with recommendations with DetailedError)",
args: args{
stepID: "git-clone",
err: step.NewErrorWithRecommendations(
"git-clone",
"tag",
errors.New("with step.Error with recommendations with DetailedError"),
"shortMsg: with step.Error with recommendations with DetailedError",
step.Recommendation{
"BranchRecommendation": []string{"master", "feature1"},
"DetailedError": map[string]string{
"Description": "Please choose another branch and try again.",
"Title": "We couldn't find the branch 'mastre'.",
},
}),
},
want: models.ScanResultModel{
ScannerToErrorsWithRecommendations: map[string]models.ErrorsWithRecommendations{
"general": {
models.ErrorWithRecommendations{
Error: "Error in step git-clone: with step.Error with recommendations with DetailedError",
Recommendations: step.Recommendation{
"BranchRecommendation": []string{"master", "feature1"},
"DetailedError": map[string]string{
"Description": "Please choose another branch and try again.",
"Title": "We couldn't find the branch 'mastre'.",
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := buildErrorScanResultModel(tt.args.stepID, tt.args.err); !reflect.DeepEqual(got, tt.want) {
t.Errorf("resultClient.buildErrorScanResultModel() = %v, want %v", got, tt.want)
}
})
}
}