Repository: google/go-github
File: github/classroom_test.go (Go)

Code before:

	const methodName = "GetAssignment"
	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Classroom.GetAssignment(ctx, 12)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestClassroomService_GetClassroom(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)

	mux.HandleFunc("/classrooms/1296269", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		fmt.Fprint(w, `{
			"id": 1296269,
			"name": "Programming Elixir",
			"archived": false,
			"organization": {
				"id": 1,
				"login": "programming-elixir",
				"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
				"html_url": "https://github.com/programming-elixir",
				"name": "Learn how to build fault tolerant applications",
				"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4"
			},
			"url": "https://classroom.github.com/classrooms/1-programming-elixir"
		}`)
	})

	ctx := context.Background()
	classroom, _, err := client.Classroom.GetClassroom(ctx, 1296269)
	if err != nil {
		t.Errorf("Classroom.GetClassroom returned error: %v", err)
	}

	want := &Classroom{
		ID:       Ptr(int64(1296269)),
		Name:     Ptr("Programming Elixir"),
		Archived: Ptr(false),
		Organization: &Organization{
			ID:        Ptr(int64(1)),
			Login:     Ptr("programming-elixir"),
			NodeID:    Ptr("MDEyOk9yZ2FuaXphdGlvbjE="),
			HTMLURL:   Ptr("https://github.com/programming-elixir"),
			Name:      Ptr("Learn how to build fault tolerant applications"),
			AvatarURL: Ptr("https://avatars.githubusercontent.com/u/9919?v=4"),
		},

Review comment (suggestion):
As much as I like Elixir and the Beam VM, please replace all URLs in this file with bogus ones, as we never want anyone to point fingers at us (this repo) for spreading external stuff for which we have no control over.

Code after:

	const methodName = "GetAssignment"
	testBadOptions(t, methodName, func() (err error) {
		_, _, err = client.Classroom.GetAssignment(ctx, -1)
		return err
	})

	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
		got, resp, err := client.Classroom.GetAssignment(ctx, 12)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestClassroomService_GetClassroom(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)

	mux.HandleFunc("/classrooms/1296269", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		fmt.Fprint(w, `{
			"id": 1296269,
			"name": "Programming Elixir",
			"archived": false,
			"organization": {
				"id": 1,
				"login": "programming-elixir",
				"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
				"html_url": "https://example.com/programming-elixir",
				"name": "Learn how to build fault tolerant applications",
				"avatar_url": "https://example.com/avatars/u/9919?v=4"
			},
			"url": "https://example.com/classrooms/programming"
		}`)
	})

	ctx := context.Background()
	classroom, _, err := client.Classroom.GetClassroom(ctx, 1296269)
	if err != nil {
		t.Errorf("Classroom.GetClassroom returned error: %v", err)
	}

	want := &Classroom{
		ID:       Ptr(int64(1296269)),
		Name:     Ptr("Programming Elixir"),
		Archived: Ptr(false),
		Organization: &Organization{
			ID:        Ptr(int64(1)),
			Login:     Ptr("programming-elixir"),