package cmd import ( "fmt" "os" "path/filepath" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "edge-infra.dev/pkg/lib/build/bazel" ) func TestCreate(t *testing.T) { tcs := []struct { path string tags []string }{ {"0103-worsening-everyones-life.md", []string{}}, {"0003-the-third-wheel.md", []string{"build", "ci", "automation", "magic"}}, } dir, err := bazel.NewTestTmpDir("dlog-create-*") require.NoError(t, err) date := time.Date(1997, time.September, 30, 0, 0, 0, 0, time.UTC) for i, tc := range tcs { t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) { template, err := os.Open("testdata/template.md") require.NoError(t, err) dlogPath := filepath.Join(dir, tc.path) assert.NoError(t, createDLog(dlogPath, template, date, tc.tags)) exp, err := os.ReadFile(fmt.Sprintf("testdata/create-expected-%d.md", i)) require.NoError(t, err) actual, err := os.ReadFile(dlogPath) require.NoError(t, err) assert.Equal(t, string(exp), string(actual)) }) } }