@@ -5,7 +5,6 @@ package immutable
5
5
import (
6
6
"context"
7
7
"testing"
8
-
9
8
"github.com/mittwald/goharbor-client/v5/apiv2/model"
10
9
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/clients/project"
11
10
clienttesting "github.com/mittwald/goharbor-client/v5/apiv2/pkg/testing"
@@ -46,4 +45,72 @@ func TestAPIImmutableListImmutableRules(t *testing.T) {
46
45
listedImmutableRuleTag := listedImmutableRules [0 ].TagSelectors
47
46
48
47
require .Equal (t , listedImmutableRuleTag [0 ], immutableRule .TagSelectors [0 ])
48
+
49
+ immuRuleID := listedImmutableRules [0 ].ID
50
+
51
+ c .DeleteImmuRule (ctx , projectName , immuRuleID )
52
+
53
+ checkDeletedImmuRules , err := c .ListImmuRules (ctx , projectName )
54
+
55
+ require .Empty (t , checkDeletedImmuRules )
49
56
}
57
+
58
+ func TestAPIImmutableUpdateImmutableRules (t * testing.T ) {
59
+ ctx := context .Background ()
60
+
61
+ c := NewClient (clienttesting .V2SwaggerClient , clienttesting .DefaultOpts , clienttesting .AuthInfo )
62
+ pc := project .NewClient (clienttesting .V2SwaggerClient , clienttesting .DefaultOpts , clienttesting .AuthInfo )
63
+
64
+ err := pc .NewProject (ctx , & model.ProjectReq {
65
+ ProjectName : projectName ,
66
+ })
67
+ require .NoError (t , err )
68
+
69
+ defer pc .DeleteProject (ctx , projectName )
70
+
71
+ createImmutableRule := model.ImmutableRule {
72
+ ScopeSelectors : map [string ][]model.ImmutableSelector {},
73
+ TagSelectors : []* model.ImmutableSelector {{
74
+ Decoration : "matches" ,
75
+ Kind : "doublestar" ,
76
+ Pattern : "1.0.0" ,
77
+ }},
78
+ }
79
+
80
+ updateImmutableRule := model.ImmutableRule {
81
+ ScopeSelectors : map [string ][]model.ImmutableSelector {},
82
+ TagSelectors : []* model.ImmutableSelector {{
83
+ Decoration : "matches" ,
84
+ Kind : "doublestar" ,
85
+ Pattern : "2.0.0" ,
86
+ }},
87
+ }
88
+
89
+ err = c .CreateImmuRule (ctx , projectName , & createImmutableRule )
90
+ require .NoError (t , err )
91
+
92
+ listedImmutableRules , err := c .ListImmuRules (ctx , projectName )
93
+
94
+ require .NoError (t , err )
95
+
96
+ immuRuleID := listedImmutableRules [0 ].ID
97
+
98
+ err = c .UpdateImmuRule (ctx , projectName , & updateImmutableRule , immuRuleID )
99
+
100
+ require .NoError (t , err )
101
+
102
+ listedImmutableRules , err = c .ListImmuRules (ctx , projectName )
103
+
104
+ require .NoError (t , err )
105
+
106
+ listedImmutableRuleTag := listedImmutableRules [0 ].TagSelectors
107
+
108
+ require .Equal (t , listedImmutableRuleTag [0 ], updateImmutableRule .TagSelectors [0 ])
109
+
110
+
111
+ c .DeleteImmuRule (ctx , projectName , immuRuleID )
112
+
113
+ checkDeletedImmuRules , err := c .ListImmuRules (ctx , projectName )
114
+
115
+ require .Empty (t , checkDeletedImmuRules )
116
+ }
0 commit comments