File: project_templates_test.go

package info (click to toggle)
golang-gitlab-gitlab-org-api-client-go 0.123.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,356 kB
  • sloc: makefile: 17
file content (69 lines) | stat: -rw-r--r-- 1,469 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gitlab

import (
	"fmt"
	"net/http"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestProjectTemplatesService_ListTemplates(t *testing.T) {
	mux, client := setup(t)

	mux.HandleFunc("/api/v4/projects/1/templates/issues", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		fmt.Fprintf(w, `
			[
				{
					"key": "epl-1.0",
					"name": "Eclipse Public License 1.0"
				  },
				  {
					"key": "lgpl-3.0",
					"name": "GNU Lesser General Public License v3.0"
				  }
			]
		`)
	})

	want := []*ProjectTemplate{
		{
			Key:  "epl-1.0",
			Name: "Eclipse Public License 1.0",
		},
		{
			Key:  "lgpl-3.0",
			Name: "GNU Lesser General Public License v3.0",
		},
	}

	ss, resp, err := client.ProjectTemplates.ListTemplates(1, "issues", nil, nil)
	require.NoError(t, err)
	require.NotNil(t, resp)
	require.Equal(t, want, ss)
}

func TestProjectTemplatesService_GetProjectTemplate(t *testing.T) {
	mux, client := setup(t)

	mux.HandleFunc("/api/v4/projects/1/templates/issues/test_issue", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		fmt.Fprintf(w, `
			{
			  "name": "test_issue",
			  "content": "## Test"
			}
		`)
	})

	want := &ProjectTemplate{
		Name:    "test_issue",
		Content: "## Test",
	}

	ss, resp, err := client.ProjectTemplates.GetProjectTemplate(1, "issues", "test_issue", nil, nil)
	require.NoError(t, err)
	require.NotNil(t, resp)
	require.Equal(t, want, ss)
}