Debian Codegraph @

github/repos_properties_test.go

raw
1 // Copyright 2023 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "net/http"
12 "testing"
13
14 "github.com/google/go-cmp/cmp"
15 )
16
17 func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
18 client, mux, _, teardown := setup()
19 defer teardown()
20
21 mux.HandleFunc("/repos/o/r/properties/values", func(w http.ResponseWriter, r *http.Request) {
22 testMethod(t, r, "GET")
23 fmt.Fprint(w, `[
24 {
25 "property_name": "environment",
26 "value": "production"
27 },
28 {
29 "property_name": "service",
30 "value": "web"
31 }
32 ]`)
33 })
34
35 ctx := context.Background()
36 customPropertyValues, _, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r")
37 if err != nil {
38 t.Errorf("Repositories.GetAllCustomPropertyValues returned error: %v", err)
39 }
40
41 want := []*CustomPropertyValue{
42 {
43 PropertyName: "environment",
44 Value: String("production"),
45 },
46 {
47 PropertyName: "service",
48 Value: String("web"),
49 },
50 }
51
52 if !cmp.Equal(customPropertyValues, want) {
53 t.Errorf("Repositories.GetAllCustomPropertyValues returned %+v, want %+v", customPropertyValues, want)
54 }
55
56 const methodName = "GetAllCustomPropertyValues"
57
58 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
59 got, resp, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r")
60 if got != nil {
61 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
62 }
63 return resp, err
64 })
65 }