Skip to content

Commit dd3debd

Browse files
committed
fix lints
Signed-off-by: Carlos Panato <ctadeu@gmail.com>
1 parent f67edd7 commit dd3debd

File tree

10 files changed

+13
-32
lines changed

10 files changed

+13
-32
lines changed

pkg/api/bindings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
108108
// Validate the event
109109
err := Validate(event)
110110
if err != nil {
111-
return nil, fmt.Errorf("cannot validate CDEvent %v", err)
111+
return nil, fmt.Errorf("cannot validate CDEvent %w", err)
112112
}
113113
ce := cloudevents.NewEvent()
114114
ce.SetID(event.GetId())
@@ -149,10 +149,10 @@ func Validate(event CDEventReader) error {
149149
var v interface{}
150150
jsonString, err := AsJsonString(event)
151151
if err != nil {
152-
return fmt.Errorf("cannot render the event %s as json %s", event, err)
152+
return fmt.Errorf("cannot render the event %s as json %w", event, err)
153153
}
154154
if err := json.Unmarshal([]byte(jsonString), &v); err != nil {
155-
return fmt.Errorf("cannot unmarshal event json: %v", err)
155+
return fmt.Errorf("cannot unmarshal event json: %w", err)
156156
}
157157
// Validate the "validate" tags
158158
if err := validate.Struct(event); err != nil {

pkg/api/bindings_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ func init() {
239239
// TestAsCloudEvent produces a CloudEvent from a CDEvent using `AsCloudEvent`
240240
// and then attempts to parse the CloudEvent payload back into a specific CDEvent
241241
func TestAsCloudEvent(t *testing.T) {
242-
243242
tests := []struct {
244243
name string
245244
event api.CDEventReader
@@ -309,7 +308,6 @@ func TestAsCloudEvent(t *testing.T) {
309308
}
310309

311310
func TestAsCloudEventInvalid(t *testing.T) {
312-
313311
tests := []struct {
314312
name string
315313
event api.CDEventReader
@@ -353,7 +351,6 @@ func TestAsCloudEventInvalid(t *testing.T) {
353351
// rendered JSON depends on a number of factors, and is not deterministic
354352
// so we must compare events unmarshalled to an interface
355353
func TestAsJsonBytes(t *testing.T) {
356-
357354
tests := []struct {
358355
name string
359356
event api.CDEvent
@@ -409,7 +406,6 @@ func TestAsJsonBytes(t *testing.T) {
409406
}
410407

411408
func TestInvalidEvent(t *testing.T) {
412-
413409
// mandatory source missing
414410
eventNoSource, _ := testapi.NewFooSubjectBarPredicateEvent()
415411
eventNoSource.SetSubjectId(testSubjectId)
@@ -506,7 +502,6 @@ func TestAsJsonStringEmpty(t *testing.T) {
506502
}
507503

508504
func TestNewFromJsonString(t *testing.T) {
509-
510505
tests := []struct {
511506
name string
512507
event api.CDEventV04
@@ -582,7 +577,6 @@ func TestNewFromJsonString(t *testing.T) {
582577
}
583578

584579
func TestParseType(t *testing.T) {
585-
586580
tests := []struct {
587581
name string
588582
eventType string
@@ -668,7 +662,6 @@ func testEventWithVersion(eventVersion string, specVersion string) *testapi.FooS
668662
}
669663

670664
func TestNewFromJsonBytes(t *testing.T) {
671-
672665
minorVersion := testEventWithVersion("2.999.1", testapi.SpecVersion)
673666
patchVersion := testEventWithVersion("2.2.999", testapi.SpecVersion)
674667
pastPatchVersion := testEventWithVersion("2.2.0", testapi.SpecVersion)

pkg/api/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,28 +290,29 @@ func (ela *EmbeddedLinksArray) UnmarshalJSON(b []byte) error {
290290
if err != nil {
291291
return err
292292
}
293-
if m.LinkType == LinkTypeEnd {
293+
switch m.LinkType {
294+
case LinkTypeEnd:
294295
var e embeddedLinkEnd
295296
err = json.Unmarshal(*rawEmbeddedLink, &e)
296297
if err != nil {
297298
return err
298299
}
299300
receiver[index] = &e
300-
} else if m.LinkType == LinkTypePath {
301+
case LinkTypePath:
301302
var e embeddedLinkPath
302303
err = json.Unmarshal(*rawEmbeddedLink, &e)
303304
if err != nil {
304305
return err
305306
}
306307
receiver[index] = &e
307-
} else if m.LinkType == LinkTypeRelation {
308+
case LinkTypeRelation:
308309
var e embeddedLinkRelation
309310
err = json.Unmarshal(*rawEmbeddedLink, &e)
310311
if err != nil {
311312
return err
312313
}
313314
receiver[index] = &e
314-
} else {
315+
default:
315316
return fmt.Errorf("unsupported link type %s found", m.LinkType)
316317
}
317318
}

pkg/api/types_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ type testWrongType struct {
7676
}
7777

7878
func TestGetCustomDataAsNonJson(t *testing.T) {
79-
8079
receiver := &testType{}
8180
expectedError := "cannot unmarshal content-type application/xml"
8281

@@ -91,7 +90,6 @@ func TestGetCustomDataAsNonJson(t *testing.T) {
9190
}
9291

9392
func TestGetCustomDataAsJson(t *testing.T) {
94-
9593
receiver := &testType{}
9694
expectedValue := "testValue"
9795

@@ -127,7 +125,6 @@ func TestGetCustomDataAsJson(t *testing.T) {
127125
}
128126

129127
func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {
130-
131128
receiver := &testWrongType{}
132129
expectedReceiver := &testWrongType{}
133130

@@ -163,7 +160,6 @@ func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {
163160
}
164161

165162
func TestSetCustomData(t *testing.T) {
166-
167163
tests := []struct {
168164
name string
169165
contentType string
@@ -215,7 +211,6 @@ func TestSetCustomDataInvalid(t *testing.T) {
215211
}
216212

217213
func TestGetCustomData(t *testing.T) {
218-
219214
tests := []struct {
220215
name string
221216
contentType string
@@ -302,7 +297,6 @@ func TestGetCustomDataXmlNotBytes(t *testing.T) {
302297
}
303298

304299
func TestGetCustomDataRaw(t *testing.T) {
305-
306300
tests := []struct {
307301
name string
308302
contentType string

pkg/api/v03/examples_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ func exampleTestOutputPublishedEvent(e *apiv03.TestOutputPublishedEvent) {
376376
}
377377

378378
func init() {
379-
380379
// Load event examples from the spec
381380
examplesConsumed = make(map[string][]byte)
382381

@@ -394,7 +393,6 @@ func init() {
394393
// - it parses the examples into a CDEvent and
395394
// - it verifies that produced and consumed CDEvent match
396395
func TestExamples(t *testing.T) {
397-
398396
for name, exampleConsumed := range examplesConsumed {
399397
t.Run(name, func(t *testing.T) {
400398
produced, ok := examplesProduced[name]

pkg/api/v03/factory_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func TestNewCDEvent(t *testing.T) {
129129
}
130130

131131
func TestNewCDEventFailed(t *testing.T) {
132-
133132
_, err := cdevents.NewCDEvent(api.CDEventType{Subject: "not supported"}.String(), testSpecVersion)
134133
if err == nil {
135134
t.Fatalf("expected it to fail, but it didn't")

pkg/api/v04/conformance_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ func exampleCustomTypeEvent(e *apiv04.CustomTypeEvent) {
562562
// - it parses the examples into a CDEvent and
563563
// - it verifies that produced and consumed CDEvent match
564564
func TestExamples(t *testing.T) {
565-
566565
for name, exampleConsumed := range examplesConsumed {
567566
t.Run(name, func(t *testing.T) {
568567
produced, ok := examplesProduced[name]

pkg/api/v04/factory_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func TestNewCDEvent(t *testing.T) {
129129
}
130130

131131
func TestNewCDEventFailed(t *testing.T) {
132-
133132
_, err := cdevents.NewCDEvent(api.CDEventType{Subject: "not supported"}.String(), testSpecVersion)
134133
if err == nil {
135134
t.Fatalf("expected it to fail, but it didn't")

tools/generator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func loadSchemas(schemaFolder string, schemas *Schemas) error {
329329
return nil
330330
} else {
331331
// Something else went wrong
332-
return fmt.Errorf("error loading schemas from %s: %s", schemaFolder, err)
332+
return fmt.Errorf("error loading schemas from %s: %w", schemaFolder, err)
333333
}
334334
}
335335
return fs.WalkDir(os.DirFS(schemaFolder), ".", getSchemasWalkProcessor(schemaFolder, schemas))
@@ -343,7 +343,7 @@ func generate(schemaFolders []string, genFolder, prefix, specVersion string, tem
343343
Slice: make([]Data, 0),
344344
SpecVersion: specVersion,
345345
SpecVersionShort: shortSpecVersion,
346-
SpecVersionName: strings.Replace(shortSpecVersion, ".", "", -1),
346+
SpecVersionName: strings.ReplaceAll(shortSpecVersion, ".", ""),
347347
IsTestData: isTestMode,
348348
}
349349

@@ -433,14 +433,14 @@ func getSchemasWalkProcessor(rootDir string, schemas *Schemas) fs.WalkDirFunc {
433433
schemaPath := filepath.Join(rootDir, path)
434434
schemaBytes, err := os.ReadFile(schemaPath)
435435
if err != nil {
436-
return fmt.Errorf("cannot read schema file at %s: %v", schemaPath, err)
436+
return fmt.Errorf("cannot read schema file at %s: %w", schemaPath, err)
437437
}
438438
schema := struct {
439439
Id string `json:"$id"`
440440
}{}
441441
// Load the jsonschema from the spec
442442
if err := json.Unmarshal(schemaBytes, &schema); err != nil {
443-
return fmt.Errorf("cannot unmarshal schema file at %s: %v", schemaPath, err)
443+
return fmt.Errorf("cannot unmarshal schema file at %s: %w", schemaPath, err)
444444
}
445445
// If no $id is defined ignore this file
446446
if schema.Id == "" {

tools/generator_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func init() {
7272
}
7373

7474
func TestDataFromSchema(t *testing.T) {
75-
7675
want := &Data{
7776
Subject: testSubject,
7877
Predicate: testPredicate,
@@ -121,7 +120,7 @@ func TestDataFromSchema(t *testing.T) {
121120
}
122121
got, err := DataFromSchema(testSchema, mappings, "0.1.2")
123122
if err != nil {
124-
t.Fatalf(err.Error())
123+
t.Fatal(err.Error())
125124
}
126125
less := func(a, b ContentField) bool { return a.Name < b.Name }
127126
if d := cmp.Diff(want, got, cmpopts.SortSlices(less)); d != "" {
@@ -221,7 +220,6 @@ func TestExecuteTemplate_Error(t *testing.T) {
221220

222221
// TestValidateStringEnumAnyOf tests the validation of the string enum anyOf case.
223222
func TestValidateStringEnumAnyOf(t *testing.T) {
224-
225223
var boolType jsonschema.Types = 4
226224
var stringType jsonschema.Types = 32
227225
tests := []struct {

0 commit comments

Comments
 (0)