From df44dedc5eed9aab2343548cebaaacfa4708e838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Garc=C3=ADa=20Veytia=20=28Puerco=29?= Date: Fri, 15 Dec 2023 01:35:32 -0600 Subject: [PATCH] Add generate --init test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adolfo GarcĂ­a Veytia (Puerco) --- pkg/ctl/implementation_test.go | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/ctl/implementation_test.go b/pkg/ctl/implementation_test.go index 9726b95..85d3ebb 100644 --- a/pkg/ctl/implementation_test.go +++ b/pkg/ctl/implementation_test.go @@ -7,6 +7,8 @@ package ctl import ( "context" + "os" + "path/filepath" "testing" intoto "github.com/in-toto/in-toto-golang/in_toto" @@ -376,3 +378,38 @@ func TestReadGoldenData(t *testing.T) { }) } } + +func TestInitTemplatesDir(t *testing.T) { + sut := defaultVexCtlImplementation{} + for _, tc := range []struct { + name string + prepare func(string) + shouldErr bool + }{ + { + name: "normal", + prepare: func(s string) {}, + shouldErr: false, + }, + { + name: "not clean dir", + prepare: func(s string) { + require.NoError(t, os.WriteFile(filepath.Join(s, "test.txt"), []byte("abc"), os.FileMode(0o644))) + }, + shouldErr: true, + }, + } { + t.Run(tc.name, func(t *testing.T) { + dir := t.TempDir() + tc.prepare(dir) + err := sut.InitTemplatesDir(dir) + if tc.shouldErr { + require.Error(t, err) + return + } + require.FileExists(t, filepath.Join(dir, "README.md")) + require.FileExists(t, filepath.Join(dir, "main.openvex.json")) + require.NoError(t, err) + }) + } +}