Skip to content

Commit 51bb301

Browse files
Eneman DonatienEneman Donatien
authored andcommitted
[ENH] ✨ add some test and modify ci for docker image
1 parent 6ccec8e commit 51bb301

25 files changed

+568
-6
lines changed

.github/workflows/ci-docker.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ jobs:
3333

3434
- name: Docker meta
3535
id: docker_meta
36-
uses: crazy-max/ghaction-docker-meta@v5.1.0
36+
uses: docker/metadata-action@v5
3737
with:
3838
images: inseefrlab/s3-operator # list of Docker images to use as base name for tags
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
3944
4045
- name: Set up QEMU
4146
uses: docker/setup-qemu-action@v3
@@ -51,17 +56,15 @@ jobs:
5156
password: ${{ secrets.DOCKERHUB_TOKEN }}
5257

5358
- name: Build and push
54-
uses: docker/build-push-action@v5
59+
uses: docker/build-push-action@v6
5560
with:
5661
context: .
5762
file: ./Dockerfile
5863
push: ${{ github.event_name != 'pull_request' }}
59-
# Use tags computed before and also latest if on master
64+
# Use tags computed before
6065
tags: |
6166
${{ steps.docker_meta.outputs.tags }}
62-
${{ github.ref == 'refs/heads/main' && 'inseefrlab/s3-operator:latest' || '' }}
6367
labels: ${{ steps.docker_meta.outputs.labels }}
6468
platforms: linux/amd64,linux/arm64
65-
6669
- name: Image digest
6770
run: echo ${{ steps.docker_build.outputs.digest }}

internal/controller/bucket/finalizer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package bucket_controller_test
218

319
import (

internal/controller/bucket/reconcile_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,66 @@ func TestHandleCreate(t *testing.T) {
7575
assert.NoError(t, err)
7676
})
7777
}
78+
79+
func TestHandleUpdate(t *testing.T) {
80+
// Set up a logger before running tests
81+
log.SetLogger(zap.New(zap.UseDevMode(true)))
82+
83+
// Create a fake client with a sample CR
84+
bucketResource := &s3v1alpha1.Bucket{
85+
ObjectMeta: metav1.ObjectMeta{
86+
Name: "existing-bucket",
87+
Namespace: "default",
88+
Generation: 1,
89+
Finalizers: []string{"s3.onyxia.sh/finalizer"},
90+
},
91+
Spec: s3v1alpha1.BucketSpec{
92+
Name: "existing-bucket",
93+
Paths: []string{"example"},
94+
S3InstanceRef: "s3-operator/default",
95+
Quota: s3v1alpha1.Quota{Default: 10},
96+
},
97+
}
98+
99+
// Create a fake client with a sample CR
100+
bucketInvalidResource := &s3v1alpha1.Bucket{
101+
ObjectMeta: metav1.ObjectMeta{
102+
Name: "existing-invalid-bucket",
103+
Namespace: "default",
104+
Generation: 1,
105+
Finalizers: []string{"s3.onyxia.sh/finalizer"},
106+
},
107+
Spec: s3v1alpha1.BucketSpec{
108+
Name: "existing-invalid-bucket",
109+
Paths: []string{"example", "non-existing"},
110+
S3InstanceRef: "s3-operator/default",
111+
Quota: s3v1alpha1.Quota{Default: 100}},
112+
}
113+
114+
// Add mock for s3Factory and client
115+
testUtils := TestUtils.NewTestUtils()
116+
testUtils.SetupMockedS3FactoryAndClient()
117+
s3instanceResource, secretResource := testUtils.GenerateBasicS3InstanceAndSecret()
118+
testUtils.SetupClient([]client.Object{s3instanceResource, secretResource, bucketResource, bucketInvalidResource})
119+
120+
// Create the reconciler
121+
reconciler := &bucket_controller.BucketReconciler{
122+
Client: testUtils.Client,
123+
Scheme: testUtils.Client.Scheme(),
124+
S3factory: testUtils.S3Factory,
125+
}
126+
127+
t.Run("no error", func(t *testing.T) {
128+
// Call Reconcile function
129+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: bucketResource.Name, Namespace: bucketResource.Namespace}}
130+
_, err := reconciler.Reconcile(context.TODO(), req)
131+
assert.NoError(t, err)
132+
})
133+
134+
t.Run("no error", func(t *testing.T) {
135+
// Call Reconcile function
136+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: bucketInvalidResource.Name, Namespace: bucketInvalidResource.Namespace}}
137+
_, err := reconciler.Reconcile(context.TODO(), req)
138+
assert.NoError(t, err)
139+
})
140+
}

internal/controller/path/finalizer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package path_controller_test
218

319
import (

internal/controller/path/reconcile_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package path_controller_test
218

319
import (
@@ -55,3 +71,86 @@ func TestHandleCreate(t *testing.T) {
5571
assert.NoError(t, err)
5672
})
5773
}
74+
75+
func TestHandleUpdate(t *testing.T) {
76+
// Set up a logger before running tests
77+
log.SetLogger(zap.New(zap.UseDevMode(true)))
78+
79+
// Create a fake client with a sample CR
80+
pathResource := &s3v1alpha1.Path{
81+
ObjectMeta: metav1.ObjectMeta{
82+
Name: "existing-path",
83+
Namespace: "default",
84+
Generation: 1,
85+
Finalizers: []string{"s3.onyxia.sh/finalizer"},
86+
},
87+
Spec: s3v1alpha1.PathSpec{
88+
BucketName: "existing-bucket",
89+
S3InstanceRef: "s3-operator/default",
90+
Paths: []string{"example"},
91+
},
92+
}
93+
94+
// Create a fake client with a sample CR
95+
pathInvalidResource := &s3v1alpha1.Path{
96+
ObjectMeta: metav1.ObjectMeta{
97+
Name: "existing-invalid-paths",
98+
Namespace: "default",
99+
Generation: 1,
100+
Finalizers: []string{"s3.onyxia.sh/finalizer"},
101+
},
102+
Spec: s3v1alpha1.PathSpec{
103+
BucketName: "existing-invalid-bucket",
104+
S3InstanceRef: "s3-operator/default",
105+
Paths: []string{"example", "non-existing"},
106+
},
107+
}
108+
109+
pathInvalidResource2 := &s3v1alpha1.Path{
110+
ObjectMeta: metav1.ObjectMeta{
111+
Name: "existing-invalid-paths2",
112+
Namespace: "default",
113+
Generation: 1,
114+
Finalizers: []string{"s3.onyxia.sh/finalizer"},
115+
},
116+
Spec: s3v1alpha1.PathSpec{
117+
BucketName: "non-existing-bucket",
118+
S3InstanceRef: "s3-operator/default",
119+
Paths: []string{"example", "non-existing"},
120+
},
121+
}
122+
123+
// Add mock for s3Factory and client
124+
testUtils := TestUtils.NewTestUtils()
125+
testUtils.SetupMockedS3FactoryAndClient()
126+
s3instanceResource, secretResource := testUtils.GenerateBasicS3InstanceAndSecret()
127+
testUtils.SetupClient([]client.Object{s3instanceResource, secretResource, pathResource, pathInvalidResource, pathInvalidResource2})
128+
129+
// Create the reconciler
130+
reconciler := &path_controller.PathReconciler{
131+
Client: testUtils.Client,
132+
Scheme: testUtils.Client.Scheme(),
133+
S3factory: testUtils.S3Factory,
134+
}
135+
136+
t.Run("no error", func(t *testing.T) {
137+
// Call Reconcile function
138+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: pathResource.Name, Namespace: pathResource.Namespace}}
139+
_, err := reconciler.Reconcile(context.TODO(), req)
140+
assert.NoError(t, err)
141+
})
142+
143+
t.Run("no error on invalid resource", func(t *testing.T) {
144+
// Call Reconcile function
145+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: pathInvalidResource.Name, Namespace: pathInvalidResource.Namespace}}
146+
_, err := reconciler.Reconcile(context.TODO(), req)
147+
assert.NoError(t, err)
148+
})
149+
150+
t.Run("failed create path on non existing bucket", func(t *testing.T) {
151+
// Call Reconcile function
152+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: pathInvalidResource2.Name, Namespace: pathInvalidResource2.Namespace}}
153+
_, err := reconciler.Reconcile(context.TODO(), req)
154+
assert.NoError(t, err)
155+
})
156+
}

internal/controller/policy/finalizer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package policy_controller_test
218

319
import (

internal/controller/policy/reconcile_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package policy_controller_test
218

319
import (

internal/controller/s3instance/finalizer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package s3instance_controller_test
218

319
import (

internal/controller/s3instance/reconcile_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package s3instance_controller_test
218

319
import (

internal/controller/user/finalizer_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
118
package user_controller_test
219

320
import (

0 commit comments

Comments
 (0)