-
Notifications
You must be signed in to change notification settings - Fork 16
/
service_test.go
55 lines (50 loc) · 1.21 KB
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package render
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/akuity/kargo-render/internal/file"
)
func TestNewService(t *testing.T) {
s := NewService(nil)
svc, ok := s.(*service)
require.True(t, ok)
require.NotNil(t, svc.logger)
require.NotNil(t, svc.renderFn)
}
func TestWriteAppManifests(t *testing.T) {
testYAMLChunk1 := []byte(`kind: Deployment
metadata:
name: foobar
`)
testYAMLChunk2 := []byte(`kind: Service
metadata:
name: foobar
`)
testYAMLBytes := bytes.Join(
[][]byte{
testYAMLChunk1,
testYAMLChunk2,
},
[]byte("---\n"),
)
testDir := t.TempDir()
err := writeManifests(testDir, testYAMLBytes)
require.NoError(t, err)
filename := filepath.Join(testDir, "foobar-deployment.yaml")
exists, err := file.Exists(filename)
require.NoError(t, err)
require.True(t, exists)
fileBytes, err := os.ReadFile(filename)
require.NoError(t, err)
require.Equal(t, testYAMLChunk1, fileBytes)
filename = filepath.Join(testDir, "foobar-service.yaml")
exists, err = file.Exists(filename)
require.NoError(t, err)
require.True(t, exists)
fileBytes, err = os.ReadFile(filename)
require.NoError(t, err)
require.Equal(t, testYAMLChunk2, fileBytes)
}