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

Code before:
		got, resp, err := client.Organizations.CreateCodeSecurityConfiguration(ctx, "o", input)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_GetDefaultCodeSecurityConfigurations(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)
	ctx := context.Background()

	mux.HandleFunc("/orgs/o/code-security/configurations/defaults", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		fmt.Fprint(w, `[
		{
			"default_for_new_repos": "public",
			"configuration": {
				"id":1,
				"name":"config1",
				"code_scanning_default_setup": "enabled"
			}
		},
		{
			"default_for_new_repos": "private",
			"configuration": {
				"id":2,
				"name":"config2",
				"private_vulnerability_reporting": "enabled"
			}
		}
	]`)
	})

	configurations, _, err := client.Organizations.GetDefaultCodeSecurityConfigurations(ctx, "o")
	if err != nil {
		t.Errorf("Organizations.GetDefaultCodeSecurityConfigurations returned error: %v", err)
	}

	want := []*CodeSecurityConfigurationWithDefaultForNewRepos{
		{DefaultForNewRepos: Ptr("public"), Configuration: &CodeSecurityConfiguration{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")}},
		{DefaultForNewRepos: Ptr("private"), Configuration: &CodeSecurityConfiguration{ID: Ptr(int64(2)), Name: Ptr("config2"), PrivateVulnerabilityReporting: Ptr("enabled")}},
	}
	if !cmp.Equal(configurations, want) {
		t.Errorf("Organizations.GetDefaultCodeSecurityConfigurations returned %+v, want %+v", configurations, want)
	}

	const methodName = "GetDefaultCodeSecurityConfigurations"
	testBadOptions(t, methodName, func() (err error) {
		_, _, err = client.Organizations.GetDefaultCodeSecurityConfigurations(ctx, "\n")

Review comment (security):
`private` is not an allowed value here. See https://docs.github.com/en/rest/code-security/configurations?apiVersion=2022-11-28#get-default-code-security-configurations

Code after:
		got, resp, err := client.Organizations.CreateCodeSecurityConfiguration(ctx, "o", input)
		if got != nil {
			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
		}
		return resp, err
	})
}

func TestOrganizationsService_GetDefaultCodeSecurityConfigurations(t *testing.T) {
	t.Parallel()
	client, mux, _ := setup(t)
	ctx := context.Background()

	mux.HandleFunc("/orgs/o/code-security/configurations/defaults", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, "GET")
		fmt.Fprint(w, `[
		{
			"default_for_new_repos": "public",
			"configuration": {
				"id":1,
				"name":"config1",
				"code_scanning_default_setup": "enabled"
			}
		},
		{
			"default_for_new_repos": "private_and_internal",
			"configuration": {
				"id":2,
				"name":"config2",
				"private_vulnerability_reporting": "enabled"
			}
		}
	]`)
	})

	configurations, _, err := client.Organizations.GetDefaultCodeSecurityConfigurations(ctx, "o")
	if err != nil {
		t.Errorf("Organizations.GetDefaultCodeSecurityConfigurations returned error: %v", err)
	}

	want := []*CodeSecurityConfigurationWithDefaultForNewRepos{
		{DefaultForNewRepos: Ptr("public"), Configuration: &CodeSecurityConfiguration{ID: Ptr(int64(1)), Name: Ptr("config1"), CodeScanningDefaultSetup: Ptr("enabled")}},
		{DefaultForNewRepos: Ptr("private_and_internal"), Configuration: &CodeSecurityConfiguration{ID: Ptr(int64(2)), Name: Ptr("config2"), PrivateVulnerabilityReporting: Ptr("enabled")}},
	}
	if !cmp.Equal(configurations, want) {
		t.Errorf("Organizations.GetDefaultCodeSecurityConfigurations returned %+v, want %+v", configurations, want)
	}

	const methodName = "GetDefaultCodeSecurityConfigurations"
	testBadOptions(t, methodName, func() (err error) {
		_, _, err = client.Organizations.GetDefaultCodeSecurityConfigurations(ctx, "\n")