Verified Commit d7f05da5 authored by José M. Requena Plens's avatar José M. Requena Plens Committed by GitLab
Browse files

feat(snippets): add the four fields the snippet entity sends to Snippet

Changelog: Improvements
parent 24eff8f6
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -95,7 +95,11 @@ func TestProjectSnippetsService_GetSnippet(t *testing.T) {
			  },
			  "project_id": 1,
			  "web_url": "http://example.com/example/example/snippets/1",
			  "raw_url": "http://example.com/example/example/snippets/1/raw"
			  "raw_url": "http://example.com/example/example/snippets/1/raw",
			  "ssh_url_to_repo": "ssh://git@gitlab.example.com/example/example/snippets/1.git",
			  "http_url_to_repo": "https://gitlab.example.com/example/example/snippets/1.git",
			  "imported": true,
			  "imported_from": "github"
			}
		`)
	})
@@ -115,6 +119,10 @@ func TestProjectSnippetsService_GetSnippet(t *testing.T) {
		ProjectID:     1,
		WebURL:        "http://example.com/example/example/snippets/1",
		RawURL:        "http://example.com/example/example/snippets/1/raw",
		SSHURLToRepo:  "ssh://git@gitlab.example.com/example/example/snippets/1.git",
		HTTPURLToRepo: "https://gitlab.example.com/example/example/snippets/1.git",
		Imported:      true,
		ImportedFrom:  "github",
	}

	s, resp, err := client.ProjectSnippets.GetSnippet(1, 1, nil, nil)
+4 −0
Original line number Diff line number Diff line
@@ -70,7 +70,11 @@ type Snippet struct {
	ProjectID         int64         `json:"project_id"`
	WebURL            string        `json:"web_url"`
	RawURL            string        `json:"raw_url"`
	SSHURLToRepo      string        `json:"ssh_url_to_repo"`
	HTTPURLToRepo     string        `json:"http_url_to_repo"`
	Files             []SnippetFile `json:"files"`
	Imported          bool          `json:"imported"`
	ImportedFrom      string        `json:"imported_from"`
	RepositoryStorage string        `json:"repository_storage"`
}

+16 −2
Original line number Diff line number Diff line
@@ -37,13 +37,27 @@ func TestSnippetsService_GetSnippet(t *testing.T) {

	mux.HandleFunc("/api/v4/snippets/1", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		fmt.Fprint(w, `{"id":1, "title":"test"}`)
		fmt.Fprint(w, `{
			"id":1,
			"title":"test",
			"ssh_url_to_repo":"ssh://git@gitlab.example.com/snippets/1.git",
			"http_url_to_repo":"https://gitlab.example.com/snippets/1.git",
			"imported":false,
			"imported_from":"none"
		}`)
	})

	s, _, err := client.Snippets.GetSnippet(1)
	require.NoError(t, err)

	want := &Snippet{ID: 1, Title: "test"}
	want := &Snippet{
		ID:            1,
		Title:         "test",
		SSHURLToRepo:  "ssh://git@gitlab.example.com/snippets/1.git",
		HTTPURLToRepo: "https://gitlab.example.com/snippets/1.git",
		Imported:      false,
		ImportedFrom:  "none",
	}
	require.Equal(t, want, s)
}