Skip to content

Commit 660256e

Browse files
authored
Replace misc type with standard library type (#100)
Replace misc type with standard library type
1 parent d83f55e commit 660256e

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package config_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/setlog/trivrost/pkg/launcher/config"
8+
"github.com/setlog/trivrost/pkg/system"
9+
)
10+
11+
func TestDeploymentConfigWithTemplates(t *testing.T) {
12+
f, err := os.Open("test/dpc_template.json")
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
defer f.Close()
17+
configString, err := config.ReadDeploymentConfig(f, "AmigaOS", "68000x16")
18+
if err != nil {
19+
t.Fatal(err)
20+
}
21+
expectedConfigString := string(system.MustReadFile("test/dpc_template.expected.json"))
22+
if configString != expectedConfigString {
23+
t.Fatalf("Files do not match. Expected: \n%s\nActual:\n%s\n", expectedConfigString, configString)
24+
}
25+
}

pkg/launcher/config/template.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ package config
22

33
import (
44
"fmt"
5+
"strings"
56
"text/template"
6-
7-
"github.com/setlog/trivrost/pkg/misc"
87
)
98

109
type templateFields struct {
@@ -18,11 +17,11 @@ func expandPlaceholders(s string, os string, arch string) (string, error) {
1817
return "", fmt.Errorf("Could not parse template: %v", err)
1918
}
2019

21-
dw := &misc.ByteSliceWriter{}
22-
err = tmpl.Execute(dw, templateFields{os, arch})
20+
sb := &strings.Builder{}
21+
err = tmpl.Execute(sb, templateFields{os, arch})
2322
if err != nil {
2423
return "", fmt.Errorf("Could not execute template: %v", err)
2524
}
2625

27-
return string(dw.Data), nil
26+
return sb.String(), nil
2827
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"LauncherUpdate": [
3+
{
4+
"BundleInfoURL": "https://example.com/windows/launcher/bundleinfo.json",
5+
"TargetPlatforms": [ "AmigaOS-68000x16" ]
6+
}
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"LauncherUpdate": [
3+
{
4+
"BundleInfoURL": "https://example.com/windows/launcher/bundleinfo.json",
5+
"TargetPlatforms": [ "{{.OS}}-{{.Arch}}" ]
6+
}
7+
]
8+
}

pkg/misc/slicewriter.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)