github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/github/issue_test.go (about)

     1  package github
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kubeshop/testkube/pkg/api/v1/testkube"
     7  )
     8  
     9  func TestBuildTicket(t *testing.T) {
    10  	tests := []struct {
    11  		name      string
    12  		debugInfo testkube.DebugInfo
    13  		wantTitle string
    14  		wantBody  string
    15  		wantErr   bool
    16  	}{
    17  		{
    18  			name:      "Empty DebugInfo",
    19  			debugInfo: testkube.DebugInfo{},
    20  			wantErr:   true,
    21  		},
    22  		{
    23  			name: "Debug info populated",
    24  			debugInfo: testkube.DebugInfo{
    25  				ClientVersion:  "v0.test",
    26  				ServerVersion:  "v1.test",
    27  				ClusterVersion: "v2.test",
    28  				ApiLogs:        []string{"api logline1", "api logline2"},
    29  				OperatorLogs:   []string{"operator logline1", "operator logline2", "operator logline3"},
    30  				ExecutionLogs: map[string][]string{
    31  					"execution1": {"execution logline1"},
    32  					"execution2": {"execution logline1", "execution logline2"},
    33  				},
    34  			},
    35  			wantTitle: "New bug report",
    36  			wantBody: `
    37  **Describe the bug**
    38  A clear and concise description of what the bug is.
    39  
    40  **To Reproduce**
    41  Steps to reproduce the behavior:
    42  1. Run '...'
    43  2. Specify '...'
    44  3. See error
    45  
    46  **Expected behavior**
    47  A clear and concise description of what you expected to happen.
    48  
    49  **Version / Cluster**
    50  - Testkube CLI version: v0.test
    51  - Testkube API server version: v1.test
    52  - Kubernetes cluster version: v2.test
    53  
    54  **Screenshots**
    55  If applicable, add CLI commands/output to help explain your problem.
    56  
    57  **Additional context**
    58  Add any other context about the problem here.
    59  
    60  Attach the output of the **testkube debug info** command to provide more details.
    61  `,
    62  			wantErr: false,
    63  		},
    64  	}
    65  	for _, tt := range tests {
    66  		t.Run(tt.name, func(t *testing.T) {
    67  			gotTitle, gotBody, err := buildTicket(tt.debugInfo)
    68  			if (err != nil) != tt.wantErr {
    69  				t.Errorf("BuildTicket() error = %v, wantErr %v", err, tt.wantErr)
    70  				return
    71  			}
    72  			if gotTitle != tt.wantTitle {
    73  				t.Errorf("BuildTicket() title = %v, want %v", gotTitle, tt.wantTitle)
    74  			}
    75  			if gotBody != tt.wantBody {
    76  				t.Errorf("BuildTicket() body = %v, want %v", gotBody, tt.wantBody)
    77  			}
    78  		})
    79  	}
    80  }