github.com/jfrog/frogbot/v2@v2.21.0/utils/outputwriter/outputwriter_test.go (about)

     1  package outputwriter
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestMarkdownComment(t *testing.T) {
    11  	text := ""
    12  	result := MarkdownComment(text)
    13  	expected := "\n\n[comment]: <> ()\n"
    14  	assert.Equal(t, expected, result)
    15  
    16  	text = "This is a comment"
    17  	result = MarkdownComment(text)
    18  	expected = "\n\n[comment]: <> (This is a comment)\n"
    19  	assert.Equal(t, expected, result)
    20  }
    21  
    22  func TestMarkAsBold(t *testing.T) {
    23  	testCases := []struct {
    24  		input          string
    25  		expectedOutput string
    26  	}{
    27  		{
    28  			input:          "",
    29  			expectedOutput: "****",
    30  		},
    31  		{
    32  			input:          "bold",
    33  			expectedOutput: "**bold**",
    34  		},
    35  	}
    36  	for _, tc := range testCases {
    37  		assert.Equal(t, tc.expectedOutput, MarkAsBold(tc.input))
    38  	}
    39  }
    40  
    41  func TestMarkAsQuote(t *testing.T) {
    42  	testCases := []struct {
    43  		input          string
    44  		expectedOutput string
    45  	}{
    46  		{
    47  			input:          "",
    48  			expectedOutput: "``",
    49  		},
    50  		{
    51  			input:          "quote",
    52  			expectedOutput: "`quote`",
    53  		},
    54  	}
    55  	for _, tc := range testCases {
    56  		assert.Equal(t, tc.expectedOutput, MarkAsQuote(tc.input))
    57  	}
    58  }
    59  
    60  func TestMarkAsLink(t *testing.T) {
    61  	testCases := []struct {
    62  		content        string
    63  		url            string
    64  		expectedOutput string
    65  	}{
    66  		{
    67  			content:        "",
    68  			url:            "",
    69  			expectedOutput: "[]()",
    70  		},
    71  		{
    72  			content:        "content",
    73  			url:            "",
    74  			expectedOutput: "[content]()",
    75  		},
    76  		{
    77  			content:        "",
    78  			url:            "url",
    79  			expectedOutput: "[](url)",
    80  		},
    81  		{
    82  			content:        "content",
    83  			url:            "url",
    84  			expectedOutput: "[content](url)",
    85  		},
    86  	}
    87  	for _, tc := range testCases {
    88  		assert.Equal(t, tc.expectedOutput, MarkAsLink(tc.content, tc.url))
    89  	}
    90  }
    91  
    92  func TestSectionDivider(t *testing.T) {
    93  	assert.Equal(t, "\n---", SectionDivider())
    94  }
    95  
    96  func TestMarkAsCodeSnippet(t *testing.T) {
    97  	testCases := []struct {
    98  		input          string
    99  		expectedOutput string
   100  	}{
   101  		{
   102  			input:          "",
   103  			expectedOutput: "```\n\n```",
   104  		},
   105  		{
   106  			input:          "snippet",
   107  			expectedOutput: "```\nsnippet\n```",
   108  		},
   109  	}
   110  	for _, tc := range testCases {
   111  		assert.Equal(t, tc.expectedOutput, MarkAsCodeSnippet(tc.input))
   112  	}
   113  }
   114  
   115  func TestWriteContent(t *testing.T) {
   116  	testCases := []struct {
   117  		expectedOutput string
   118  		input          []string
   119  	}{
   120  		{
   121  			input:          []string{},
   122  			expectedOutput: "",
   123  		},
   124  		{
   125  			input:          []string{"content"},
   126  			expectedOutput: "\ncontent",
   127  		},
   128  		{
   129  			input:          []string{"contentA", "contentB", "contentC"},
   130  			expectedOutput: "\ncontentA\ncontentB\ncontentC",
   131  		},
   132  	}
   133  	for _, tc := range testCases {
   134  		builder := &strings.Builder{}
   135  		WriteContent(builder, tc.input...)
   136  		assert.Equal(t, tc.expectedOutput, builder.String())
   137  	}
   138  }