Skip to content

Commit

Permalink
Add generate --init test
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Dec 15, 2023
1 parent 30fb2bb commit df44ded
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/ctl/implementation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package ctl

import (
"context"
"os"
"path/filepath"
"testing"

intoto "github.com/in-toto/in-toto-golang/in_toto"
Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit df44ded

Please sign in to comment.