Skip to content

Commit 0a729be

Browse files
committed
linting + fix tests
1 parent c07078c commit 0a729be

File tree

10 files changed

+59
-30
lines changed

10 files changed

+59
-30
lines changed

api/v2beta1/atom_conversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestAtom_ConvertTo(t *testing.T) {
1414
convertFromAtom := getTestAtomV2()
1515
convertToAtom := &pdoknlv3.Atom{}
1616
dstRaw := conversion.Hub(convertToAtom)
17-
pdoknlv3.SetBaseURL("https://test.com")
17+
pdoknlv3.SetBaseURL("https://test.com/test")
1818
err := convertFromAtom.ConvertTo(dstRaw)
1919
if err != nil {
2020
t.Errorf("ConvertTo() error = %v", err)

api/v3/atom_validation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package v3
22

33
import (
44
"fmt"
5+
"slices"
6+
57
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
68
smoothoperatorvalidation "github.com/pdok/smooth-operator/pkg/validation"
79
apierrors "k8s.io/apimachinery/pkg/api/errors"
810
"k8s.io/apimachinery/pkg/runtime/schema"
911
"k8s.io/apimachinery/pkg/util/validation/field"
10-
"slices"
1112

1213
"strings"
1314

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.22.1
1212
github.com/onsi/gomega v1.36.2
1313
github.com/pdok/atom-generator v0.6.3
14-
github.com/pdok/smooth-operator v0.0.19
14+
github.com/pdok/smooth-operator v0.1.0
15+
github.com/peterbourgon/ff v1.7.1
1516
github.com/pkg/errors v0.9.1
1617
github.com/stretchr/testify v1.10.0
1718
github.com/traefik/traefik/v3 v3.3.4
@@ -81,7 +82,6 @@ require (
8182
github.com/modern-go/reflect2 v1.0.2 // indirect
8283
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8384
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
84-
github.com/peterbourgon/ff v1.7.1 // indirect
8585
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
8686
github.com/prometheus/client_golang v1.21.1 // indirect
8787
github.com/prometheus/client_model v0.6.1 // indirect

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
152152
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
153153
github.com/pdok/atom-generator v0.6.3 h1:wg491zQAokf6ePr1HcfVpF3mhMG2WroFPFpu14cX6Y0=
154154
github.com/pdok/atom-generator v0.6.3/go.mod h1:IlPwti5ocXDTjB4xmz0ZpHCOW/suuW5gQMfjfwPX6uM=
155-
github.com/pdok/smooth-operator v0.0.19 h1:ky7rmKkqm4R1H1TjOJZJ+TkdU/nSp2AbdtiLAkqt1QU=
156-
github.com/pdok/smooth-operator v0.0.19/go.mod h1:ohDqrUnmS7wK8TrNHJnFS/mDgf26Yhb8mtRBX3ixdr4=
155+
github.com/pdok/smooth-operator v0.1.0 h1:i1uZa3Niuh6ljl4UTGcC48sC01H3CaWHiIfK7pQTix8=
156+
github.com/pdok/smooth-operator v0.1.0/go.mod h1:przwM7mBGmNPqabyhImKVZ15WL4zbqLqH4ExbuWKhWE=
157157
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
158158
github.com/peterbourgon/ff v1.7.1 h1:xt1lxTG+Nr2+tFtysY7abFgPoH3Lug8CwYJMOmJRXhk=
159159
github.com/peterbourgon/ff v1.7.1/go.mod h1:fYI5YA+3RDqQRExmFbHnBjEeWzh9TrS8rnRpEq7XIg0=
@@ -317,6 +317,7 @@ golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY
317317
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
318318
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
319319
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
320+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
320321
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
321322
gomodules.xyz/jsonpatch/v2 v2.5.0 h1:JELs8RLM12qJGXU4u/TO3V25KW8GreMKl9pdkk14RM0=
322323
gomodules.xyz/jsonpatch/v2 v2.5.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=

internal/controller/atom_controller_test.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ func Test_getGeneratorConfig(t *testing.T) {
451451
atom *pdoknlv3.Atom
452452
ownerInfo *smoothoperatorv1.OwnerInfo
453453
}
454+
455+
maxAtom, err := GetAtom(testPath("maximum")+"input/atom.yaml", false)
456+
457+
if err != nil {
458+
t.Errorf("GetAtom() error = %v", err)
459+
}
460+
maxOwner, err := getOwnerInfo(testPath("maximum")+"input/ownerinfo.yaml", false)
461+
if err != nil {
462+
t.Errorf("getOwnerInfo() error = %v", err)
463+
}
464+
maxScenario := args{
465+
atom: maxAtom,
466+
ownerInfo: maxOwner,
467+
}
468+
454469
tests := []struct {
455470
name string
456471
args args
@@ -468,17 +483,15 @@ func Test_getGeneratorConfig(t *testing.T) {
468483
wantErr: true,
469484
},
470485
{
471-
name: "succesfull_scenario_02",
472-
args: args{
473-
atom: getAtom(testPath("maximum")+"input/atom.yaml", false),
474-
ownerInfo: getOwnerInfo(testPath("maximum")+"input/ownerinfo.yaml", false),
475-
},
486+
name: "maximum_scenario",
487+
args: maxScenario,
476488
wantConfig: getTestGeneratorConfig(testPath("maximum") + "expected-output/configmap.yaml"),
477489
wantErr: false,
478490
},
479491
}
480492
for _, tt := range tests {
481493
t.Run(tt.name, func(t *testing.T) {
494+
482495
gotConfig, err := getGeneratorConfig(tt.args.atom, tt.args.ownerInfo)
483496
if (err != nil) != tt.wantErr {
484497
t.Errorf("getGeneratorConfig() error = %v, wantErr %v", err, tt.wantErr)
@@ -496,30 +509,43 @@ func readTestFile(fileName string) (string, error) {
496509
return string(dat), err
497510
}
498511

499-
func getAtom(fileName string, ginkgo bool) *pdoknlv3.Atom {
512+
func GetAtom(fileName string, ginkgo bool) (*pdoknlv3.Atom, error) {
500513
atom := &pdoknlv3.Atom{}
501514
data, err := os.ReadFile(fileName)
502515
if ginkgo {
503516
Expect(err).NotTo(HaveOccurred())
504517
}
518+
if err != nil {
519+
return nil, err
520+
}
521+
505522
err = yaml.UnmarshalStrict(data, atom)
506523
if ginkgo {
507524
Expect(err).NotTo(HaveOccurred())
508525
}
509-
return atom
526+
if err != nil {
527+
return nil, err
528+
}
529+
return atom, nil
510530
}
511531

512-
func getOwnerInfo(fileName string, ginkgo bool) *smoothoperatorv1.OwnerInfo {
532+
func getOwnerInfo(fileName string, ginkgo bool) (*smoothoperatorv1.OwnerInfo, error) {
513533
owner := &smoothoperatorv1.OwnerInfo{}
514534
data, err := os.ReadFile(fileName)
515535
if ginkgo {
516536
Expect(err).NotTo(HaveOccurred())
517537
}
538+
if err != nil {
539+
return nil, err
540+
}
518541
err = yaml.UnmarshalStrict(data, owner)
519542
if ginkgo {
520543
Expect(err).NotTo(HaveOccurred())
521544
}
522-
return owner
545+
if err != nil {
546+
return nil, err
547+
}
548+
return owner, nil
523549
}
524550

525551
func getTestGeneratorConfig(fileName string) string {

internal/controller/middleware.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package controller
22

33
import (
4-
smoothoperatormodel "github.com/pdok/smooth-operator/model"
54
"strconv"
65
"strings"
76

7+
smoothoperatormodel "github.com/pdok/smooth-operator/model"
8+
89
pdoknlv3 "github.com/pdok/atom-operator/api/v3"
910
smoothutil "github.com/pdok/smooth-operator/pkg/util"
1011
"github.com/traefik/traefik/v3/pkg/config/dynamic"

internal/controller/test_data/maximum-atom/expected-output/configmap.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: maximum-atom-generator-9m992fkcfh
4+
name: maximum-atom-generator-mg8kmkb7c8
55
namespace: default
66
labels:
77
test: test
@@ -68,9 +68,9 @@ data:
6868
title: feed-1-title
6969
polygon: 50 5 50 10 100 10 100 5 50 5
7070
category:
71-
- term: https://srs-1.test
71+
- term: https://srs-1/test
7272
label: srs-1
73-
- term: https://srs-2.test
73+
- term: https://srs-2/test
7474
label: srs-2
7575
spatial_dataset_identifier_code: 00000000-0000-0000-0000-000000000002
7676
spatial_dataset_identifier_namespace: https://test.com
@@ -89,7 +89,7 @@ data:
8989
title: feed-2-title
9090
polygon: 50 5 50 10 100 10 100 5 50 5
9191
category:
92-
- term: https://srs-3.test
92+
- term: https://srs-3/test
9393
label: srs-3
9494
spatial_dataset_identifier_code: 00000000-0000-0000-0000-000000000004
9595
spatial_dataset_identifier_namespace: https://test-2.com
@@ -149,7 +149,7 @@ data:
149149
updated: "2006-01-02T15:04:05Z"
150150
polygon: 50 5 50 10 100 10 100 5 50 5
151151
category:
152-
- term: https://srs-1.test
152+
- term: https://srs-1/test
153153
label: srs-1
154154
- id: https://test.com/path/entry-2.xml
155155
title: entry-2-title
@@ -163,7 +163,7 @@ data:
163163
updated: "2006-01-02T15:04:05Z"
164164
polygon: 50 5 50 10 100 10 100 5 50 5
165165
category:
166-
- term: https://srs-2.test
166+
- term: https://srs-2/test
167167
label: srs-2
168168
- xmlname:
169169
space: ""
@@ -213,5 +213,5 @@ data:
213213
updated: "2006-01-02T15:04:05Z"
214214
polygon: 50 5 50 10 100 10 100 5 50 5
215215
category:
216-
- term: https://srs-3.test
216+
- term: https://srs-3/test
217217
label: srs-3

internal/controller/test_data/maximum-atom/input/atom.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ spec:
5858
miny: "10"
5959
srs:
6060
name: srs-1
61-
uri: https://srs-1.test
61+
uri: https://srs-1/test
6262
polygon:
6363
bbox:
6464
maxx: "10"
@@ -73,7 +73,7 @@ spec:
7373
- data: container/prefix-2/file-2.ext
7474
srs:
7575
name: srs-2
76-
uri: https://srs-2.test
76+
uri: https://srs-2/test
7777
polygon:
7878
bbox:
7979
maxx: "10"
@@ -102,7 +102,7 @@ spec:
102102
- data: container/prefix-3/file-4.ext
103103
srs:
104104
name: srs-3
105-
uri: https://srs-3.test
105+
uri: https://srs-3/test
106106
polygon:
107107
bbox:
108108
maxx: "10"

internal/controller/test_data/minimal-atom/expected-output/configmap.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: minimal-atom-generator-55ght59fth
4+
name: minimal-atom-generator-tmk22c7fm9
55
namespace: default
66
labels:
77
test: test
@@ -50,7 +50,7 @@ data:
5050
title: feed-title
5151
polygon: 50 5 50 10 100 10 100 5 50 5
5252
category:
53-
- term: https://srs.test
53+
- term: https://srs/test
5454
label: srs
5555
- xmlname:
5656
space: ""
@@ -86,5 +86,5 @@ data:
8686
updated: "2006-01-02T15:04:05Z"
8787
polygon: 50 5 50 10 100 10 100 5 50 5
8888
category:
89-
- term: https://srs.test
89+
- term: https://srs/test
9090
label: srs

internal/controller/test_data/minimal-atom/input/atom.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
- data: container/prefix/file.ext
2828
srs:
2929
name: srs
30-
uri: https://srs.test
30+
uri: https://srs/test
3131
polygon:
3232
bbox:
3333
maxx: "10"

0 commit comments

Comments
 (0)