44 "errors"
55 "os"
66 "testing"
7+
8+ "github.com/vektah/gqlparser/v2/gqlerror"
79)
810
911func TestGetOrganizationIDMissing (t * testing.T ) {
@@ -27,6 +29,59 @@ func TestGetOrganizationIDMissing(t *testing.T) {
2729 }
2830}
2931
32+ func TestIsResourceNotFoundError (t * testing.T ) {
33+ tests := []struct {
34+ name string
35+ err error
36+ shouldMatch bool
37+ }{
38+ {
39+ name : "nil error" ,
40+ err : nil ,
41+ shouldMatch : false ,
42+ },
43+ {
44+ name : "not found plain error" ,
45+ err : errors .New ("Resource not found" ),
46+ shouldMatch : true ,
47+ },
48+ {
49+ name : "no longer exists plain error" ,
50+ err : errors .New ("This resource no longer exists" ),
51+ shouldMatch : true ,
52+ },
53+ {
54+ name : "gqlerror.List not found" ,
55+ err : gqlerror.List {& gqlerror.Error {Message : "No Pipeline found" }},
56+ shouldMatch : true ,
57+ },
58+ {
59+ name : "gqlerror.List no longer exists" ,
60+ err : gqlerror.List {& gqlerror.Error {Message : "This resource no longer exists" }},
61+ shouldMatch : true ,
62+ },
63+ {
64+ name : "gqlerror.List unrelated" ,
65+ err : gqlerror.List {& gqlerror.Error {Message : "Network connection failed" }},
66+ shouldMatch : false ,
67+ },
68+ {
69+ name : "unrelated plain error" ,
70+ err : errors .New ("Network connection failed" ),
71+ shouldMatch : false ,
72+ },
73+ }
74+
75+ for _ , tt := range tests {
76+ t .Run (tt .name , func (t * testing.T ) {
77+ result := isResourceNotFoundError (tt .err )
78+ if result != tt .shouldMatch {
79+ t .Errorf ("isResourceNotFoundError(%v) = %v, want %v" , tt .err , result , tt .shouldMatch )
80+ }
81+ })
82+ }
83+ }
84+
3085func TestIsAlreadyExistsError (t * testing.T ) {
3186 tests := []struct {
3287 name string
@@ -63,6 +118,16 @@ func TestIsAlreadyExistsError(t *testing.T) {
63118 err : errors .New ("Resource not found" ),
64119 shouldMatch : false ,
65120 },
121+ {
122+ name : "gqlerror.List already been added" ,
123+ err : gqlerror.List {& gqlerror.Error {Message : "This pipeline has already been added to this team" }},
124+ shouldMatch : true ,
125+ },
126+ {
127+ name : "gqlerror.List unrelated" ,
128+ err : gqlerror.List {& gqlerror.Error {Message : "Network connection failed" }},
129+ shouldMatch : false ,
130+ },
66131 }
67132
68133 for _ , tt := range tests {
@@ -136,6 +201,16 @@ func TestIsActiveJobsError(t *testing.T) {
136201 err : errors .New ("Insufficient permissions" ),
137202 shouldMatch : false ,
138203 },
204+ {
205+ name : "gqlerror.List active builds" ,
206+ err : gqlerror.List {& gqlerror.Error {Message : "Cannot delete pipeline with active builds" }},
207+ shouldMatch : true ,
208+ },
209+ {
210+ name : "gqlerror.List unrelated" ,
211+ err : gqlerror.List {& gqlerror.Error {Message : "Insufficient permissions" }},
212+ shouldMatch : false ,
213+ },
139214 }
140215
141216 for _ , tt := range tests {
0 commit comments