get.porter.sh/porter@v1.3.0/pkg/docs/generator_test.go (about)

     1  package docs
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"get.porter.sh/porter/pkg/porter"
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestValidateDocsCommand(t *testing.T) {
    13  
    14  	testcases := []struct {
    15  		name        string
    16  		destination string
    17  		wantError   string
    18  	}{
    19  		{"should return error if destination doesn't exist", "/no-existing/destination/directory", "--destination %q doesn't exist"},
    20  		{"should not return error if destination exists", ".", ""},
    21  	}
    22  	for _, tc := range testcases {
    23  		t.Run(tc.name, func(t *testing.T) {
    24  			p := porter.NewTestPorter(t)
    25  			defer p.Close()
    26  
    27  			opts := DocsOptions{
    28  				Destination: tc.destination,
    29  			}
    30  			err := opts.Validate(p.Context)
    31  			if tc.wantError == "" {
    32  				require.NoError(t, err)
    33  			} else {
    34  				require.Error(t, err)
    35  				assert.Equal(t, fmt.Sprintf(tc.wantError, tc.destination), err.Error())
    36  			}
    37  		})
    38  	}
    39  }