Skip to content

Commit dddf079

Browse files
committed
Add generate --init test
Signed-off-by: Adolfo García Veytia (Puerco) <puerco@chainguard.dev>
1 parent 0a05ac3 commit dddf079

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pkg/ctl/implementation_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package ctl
77

88
import (
99
"context"
10+
"os"
11+
"path/filepath"
1012
"testing"
1113

1214
intoto "github.com/in-toto/in-toto-golang/in_toto"
@@ -376,3 +378,38 @@ func TestReadGoldenData(t *testing.T) {
376378
})
377379
}
378380
}
381+
382+
func TestInitTemplatesDir(t *testing.T) {
383+
sut := defaultVexCtlImplementation{}
384+
for _, tc := range []struct {
385+
name string
386+
prepare func(string)
387+
shouldErr bool
388+
}{
389+
{
390+
name: "normal",
391+
prepare: func(s string) {},
392+
shouldErr: false,
393+
},
394+
{
395+
name: "not clean dir",
396+
prepare: func(s string) {
397+
require.NoError(t, os.WriteFile(filepath.Join(s, "test.txt"), []byte("abc"), os.FileMode(0o644)))
398+
},
399+
shouldErr: true,
400+
},
401+
} {
402+
t.Run(tc.name, func(t *testing.T) {
403+
dir := t.TempDir()
404+
tc.prepare(dir)
405+
err := sut.InitTemplatesDir(dir)
406+
if tc.shouldErr {
407+
require.Error(t, err)
408+
return
409+
}
410+
require.FileExists(t, filepath.Join(dir, "README.md"))
411+
require.FileExists(t, filepath.Join(dir, "main.openvex.json"))
412+
require.NoError(t, err)
413+
})
414+
}
415+
}

0 commit comments

Comments
 (0)