...

Source file src/edge-infra.dev/pkg/f8n/devinfra/jack/plugin/pr_project/handler_test.go

Documentation: edge-infra.dev/pkg/f8n/devinfra/jack/plugin/pr_project

     1  package prproject
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"edge-infra.dev/pkg/lib/logging"
     8  
     9  	"github.com/google/go-github/v47/github"
    10  
    11  	"edge-infra.dev/pkg/f8n/devinfra/jack/plugin"
    12  )
    13  
    14  var c = &plugin.MockGithubClient{
    15  	GithubIssues:        &plugin.MockIssueService{},
    16  	GithubProjects:      &plugin.MockProjectsService{},
    17  	GithubOrganizations: &plugin.MockOrganizationsService{},
    18  }
    19  var cv4 = &plugin.MockGithubV4Client{}
    20  var projectIDs = &plugin.ProjectPlugin{
    21  	IDs: []int64{1},
    22  }
    23  var orp = &plugin.OrgRepoPlugins{
    24  	Project: *projectIDs,
    25  }
    26  var hp = &plugin.HandlerParams{
    27  	Ctx:      context.Background(),
    28  	Client:   c,
    29  	ClientV4: cv4,
    30  	Org:      "some-org",
    31  	Repo:     "some-repo",
    32  	Log:      *logging.NewLogger(),
    33  	Params:   *orp,
    34  }
    35  
    36  func TestPrClosed(_ *testing.T) {
    37  	projectIDs.IDs = []int64{150}
    38  	orp = &plugin.OrgRepoPlugins{
    39  		Project: *projectIDs,
    40  	}
    41  	hp.Params = *orp
    42  
    43  	c.GithubOrganizations = &plugin.MockOrganizationsService{
    44  		Login:    hp.Org,
    45  		Name:     hp.Org,
    46  		URL:      hp.Org,
    47  		Projects: []int{2},
    48  	}
    49  	merged := false
    50  	sha := ""
    51  	pe := &github.PullRequestEvent{
    52  		Action: github.String("closed"),
    53  		Repo: &github.Repository{
    54  			Owner: &github.User{Login: github.String(hp.Org)},
    55  			Organization: &github.Organization{
    56  				Login: github.String(hp.Org),
    57  				Name:  github.String(hp.Org),
    58  				URL:   github.String(hp.Org),
    59  			},
    60  		},
    61  		PullRequest: &github.PullRequest{
    62  			Merged:         &merged,
    63  			MergeCommitSHA: &sha,
    64  		},
    65  	}
    66  
    67  	handlePR(*hp, *pe)
    68  }
    69  
    70  func TestGetFieldVersion(t *testing.T) {
    71  	field := ProjectV2SingleSelectField{
    72  		ID: 123,
    73  		Options: []fieldOption{
    74  			fieldOption{
    75  				ID:   "1",
    76  				Name: "0.19",
    77  			},
    78  			fieldOption{
    79  				ID:   "2",
    80  				Name: "0.20",
    81  			},
    82  		},
    83  	}
    84  	if id, err := getMatchingVersionOption(field, "0.20.15"); id != "2" || err != nil {
    85  		t.Error("Failed to get version for 0.20")
    86  	}
    87  	if id, err := getMatchingVersionOption(field, "0.19.15"); id != "1" || err != nil {
    88  		t.Error("Failed to get version for 0.19")
    89  	}
    90  	if id, err := getMatchingVersionOption(field, "0.21"); id != "" || err != errReleaseNotFound {
    91  		t.Error("Getting version 0.21 did not fail")
    92  	}
    93  }
    94  

View as plain text