Skip to content

Commit

Permalink
change how to remove EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisonB319 committed Apr 17, 2024
1 parent aff3190 commit 0bb5cad
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
11 changes: 0 additions & 11 deletions pkg/agent/datamodel/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ func IndentString(original string, spaces int) string {
return out.String()
}

func trimEOF(data []byte) []byte {
eofIndex := bytes.LastIndex(data, []byte("#EOF"))
if eofIndex != -1 { // #EOF found
newlineIndex := bytes.LastIndex(data[:eofIndex], []byte("\n"))
if newlineIndex != -1 {
return data[:newlineIndex]
}
}
return data
}

func processContainerImageTag(downloadURL string) (string, error) {
// example URL "downloadURL": "mcr.microsoft.com/oss/kubernetes/autoscaler/addon-resizer:*",
// getting the data between the last / and the last :
Expand Down
26 changes: 0 additions & 26 deletions pkg/agent/datamodel/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,29 +346,3 @@ func TestIndentString(t *testing.T) {
})
}
}

func TestTrimEOF(t *testing.T) {
tests := []struct {
name string
input []byte
expected string
}{
{
name: "Should remove #EOF at the end of a file",
input: []byte(`"versions":["1.26.6","1.26.10","1.26.12","1.27.3","1.27.7","1.27.9","1.28.1","1.28.3","1.28.5","1.29.0","1.29.2"]},"_template":{"fileName":"","downloadLocation":"","downloadURL":"","versions":[]}}` + "\n#EOF"), //nolint:lll
expected: `"versions":["1.26.6","1.26.10","1.26.12","1.27.3","1.27.7","1.27.9","1.28.1","1.28.3","1.28.5","1.29.0","1.29.2"]},"_template":{"fileName":"","downloadLocation":"","downloadURL":"","versions":[]}}`, //nolint:lll
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
got := trimEOF(test.input)
diff := cmp.Diff(test.expected, string(got))
if diff != "" {
t.Fatalf(diff)
}
})
}
}
3 changes: 2 additions & 1 deletion pkg/agent/datamodel/sig_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datamodel

import (
"bytes"
_ "embed"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -958,7 +959,7 @@ func getCachedVersionsFromManifestJSON(manifestFilePath string) {
if err != nil {
panic(err)
}
data = trimEOF(data)
data = bytes.ReplaceAll(data, []byte("#EOF"), []byte(""))
var manifest Manifest
if err = json.Unmarshal(data, &manifest); err != nil {
panic(err)
Expand Down

0 comments on commit 0bb5cad

Please sign in to comment.