MCPcopy Create free account
hub / github.com/cli/cli / TestFindVersion

Function TestFindVersion

pkg/cmd/issue/artifact/shared/shared_test.go:563–641  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

561}
562
563func TestFindVersion(t *testing.T) {
564 // Artifact 2 on the spec's issue 142 keeps its versions newest first.
565 // Version 9 renamed it.
566 oauthPlan := &client.ArtifactWithVersions{
567 Number: 2, Type: "generic", Name: "OAuth callback plan", Body: "# OAuth callback plan",
568 Versions: []client.Version{
569 {Version: 12, Name: "OAuth callback plan", Body: "# OAuth callback plan"},
570 {Version: 9, Name: "OAuth callback plan", Body: "# OAuth callback plan"},
571 {Version: 5, Name: "OAuth plan", Body: "# OAuth plan\n\n1. Register the callback URL."},
572 {Version: 1, Name: "OAuth plan", Body: "# OAuth plan"},
573 },
574 }
575 // An artifact from a list, which has no edit history.
576 listed := &client.ArtifactWithVersions{
577 Number: 5, Type: "generic", Name: "Barista feedback notes",
578 }
579
580 tests := []struct {
581 name string
582 artifact *client.ArtifactWithVersions
583 number int
584 want *client.Version
585 wantErr string
586 }{
587 {
588 name: "0 means the current version",
589 artifact: oauthPlan,
590 number: 0,
591 },
592 {
593 name: "the current version's number means the current version",
594 artifact: oauthPlan,
595 number: 12,
596 },
597 {
598 name: "an earlier version",
599 artifact: oauthPlan,
600 number: 5,
601 want: &client.Version{Version: 5, Name: "OAuth plan", Body: "# OAuth plan\n\n1. Register the callback URL."},
602 },
603 {
604 name: "the first version",
605 artifact: oauthPlan,
606 number: 1,
607 want: &client.Version{Version: 1, Name: "OAuth plan", Body: "# OAuth plan"},
608 },
609 {
610 name: "a version the API didn't return",
611 artifact: oauthPlan,
612 number: 99,
613 wantErr: "version 99 not found for artifact 2",
614 },
615 {
616 name: "0 without an edit history",
617 artifact: listed,
618 number: 0,
619 },
620 {

Callers

nothing calls this directly

Calls 3

FindVersionFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected