Skip to content

Commit 466f837

Browse files
committed
refactor: update indent to 2 with yaml.v3 and fix minor test inconsistencies
Signed-off-by: Chiman Jain <chimanjain15@gmail.com>
1 parent 2ae9d05 commit 466f837

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

pkg/lib/bundle/generate.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bundle
22

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"os"
@@ -315,12 +316,17 @@ func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels,
315316
annotations.Annotations[ChannelDefaultLabel] = channelDefault
316317
}
317318

318-
afile, err := yaml.Marshal(annotations)
319-
if err != nil {
319+
var buf bytes.Buffer
320+
encoder := yaml.NewEncoder(&buf)
321+
encoder.SetIndent(2)
322+
if err := encoder.Encode(annotations); err != nil {
323+
return nil, err
324+
}
325+
if err := encoder.Close(); err != nil {
320326
return nil, err
321327
}
322328

323-
return afile, nil
329+
return buf.Bytes(), nil
324330
}
325331

326332
// GenerateDockerfile builds Dockerfile with mediatype, manifests &

pkg/lib/bundle/validate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestValidateBundleDependencies(t *testing.T) {
3030
logger: logger,
3131
}
3232

33-
var table = []struct {
33+
table := []struct {
3434
description string
3535
mediaType string
3636
directory string
@@ -108,7 +108,7 @@ func TestValidateBundleContent(t *testing.T) {
108108
logger: logger,
109109
}
110110

111-
var table = []struct {
111+
table := []struct {
112112
description string
113113
mediaType string
114114
directory string
@@ -134,7 +134,7 @@ func TestValidateBundleContent(t *testing.T) {
134134
mediaType: RegistryV1Type,
135135
directory: "./testdata/validate/invalid_manifests_bundle/invalid_sa/",
136136
numErrors: 1,
137-
errStrings: []string{"json: cannot unmarshal number into Go struct field ObjectMeta.metadata.namespace of type string"},
137+
errStrings: []string{"json: cannot unmarshal number into Go struct field Meta.metadata.namespace of type string"},
138138
},
139139
{
140140
description: "registryv1 bundle/invalid type",

pkg/prettyunmarshaler/prettyunmarshaler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ func TestJsonUnmarshalError(t *testing.T) {
149149
//
150150
// If the data does not cause a syntax error, this function will panic.
151151
func customOffsetSyntaxError(data []byte, offset int64) *json.SyntaxError {
152-
var d *byte = nil
152+
var d byte
153153
var se *json.SyntaxError
154-
err := json.Unmarshal(data, d)
154+
err := json.Unmarshal(data, &d)
155155
if errors.As(err, &se) {
156156
se.Offset = offset
157157
return se

0 commit comments

Comments
 (0)