...

Source file src/edge-infra.dev/pkg/tools/dlog/cmd/create_test.go

Documentation: edge-infra.dev/pkg/tools/dlog/cmd

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"edge-infra.dev/pkg/lib/build/bazel"
    14  )
    15  
    16  func TestCreate(t *testing.T) {
    17  	tcs := []struct {
    18  		path string
    19  		tags []string
    20  	}{
    21  		{"0103-worsening-everyones-life.md", []string{}},
    22  		{"0003-the-third-wheel.md", []string{"build", "ci", "automation", "magic"}},
    23  	}
    24  
    25  	dir, err := bazel.NewTestTmpDir("dlog-create-*")
    26  	require.NoError(t, err)
    27  	date := time.Date(1997, time.September, 30, 0, 0, 0, 0, time.UTC)
    28  	for i, tc := range tcs {
    29  		t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) {
    30  			template, err := os.Open("testdata/template.md")
    31  			require.NoError(t, err)
    32  			dlogPath := filepath.Join(dir, tc.path)
    33  			assert.NoError(t, createDLog(dlogPath, template, date, tc.tags))
    34  
    35  			exp, err := os.ReadFile(fmt.Sprintf("testdata/create-expected-%d.md", i))
    36  			require.NoError(t, err)
    37  			actual, err := os.ReadFile(dlogPath)
    38  			require.NoError(t, err)
    39  			assert.Equal(t, string(exp), string(actual))
    40  		})
    41  	}
    42  }
    43  

View as plain text