github.com/oam-dev/kubevela@v1.9.11/references/docgen/provider_test.go (about)

     1  /*
     2   Copyright 2023 The KubeVela Authors.
     3  
     4   Licensed under the Apache License, Version 2.0 (the "License");
     5   you may not use this file except in compliance with the License.
     6   You may obtain a copy of the License at
     7  
     8   	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10   Unless required by applicable law or agreed to in writing, software
    11   distributed under the License is distributed on an "AS IS" BASIS,
    12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   See the License for the specific language governing permissions and
    14   limitations under the License.
    15  */
    16  
    17  package docgen
    18  
    19  import (
    20  	"bytes"
    21  	"context"
    22  	"io"
    23  	"os"
    24  	"path/filepath"
    25  	"testing"
    26  	"time"
    27  
    28  	"github.com/stretchr/testify/assert"
    29  	"github.com/stretchr/testify/require"
    30  )
    31  
    32  func TestGenerateProvidersMarkdown(t *testing.T) {
    33  	// depends on cuegen testdata
    34  	path := "../cuegen/generators/provider/testdata"
    35  
    36  	src, err := os.ReadFile(filepath.Join(path, "valid.cue"))
    37  	require.NoError(t, err)
    38  
    39  	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    40  	defer cancel()
    41  
    42  	got := bytes.NewBuffer(nil)
    43  	err = GenerateProvidersMarkdown(ctx, []io.Reader{bytes.NewBuffer(src)}, got)
    44  	require.NoError(t, err)
    45  
    46  	expected, err := os.ReadFile(filepath.Join(path, "valid.md"))
    47  	require.NoError(t, err)
    48  
    49  	assert.Equal(t, string(expected), got.String())
    50  }