|
| 1 | +package dependency_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/githubnext/apm/internal/models/dependency" |
| 7 | +) |
| 8 | + |
| 9 | +// TestParityGitRefBranch mirrors test: parse_git_reference("main") -> (BRANCH, "main") |
| 10 | +func TestParityGitRefBranch(t *testing.T) { |
| 11 | + refType, ref := dependency.ParseGitReference("main") |
| 12 | + if refType != dependency.GitRefBranch { |
| 13 | + t.Errorf("expected BRANCH, got %s", refType) |
| 14 | + } |
| 15 | + if ref != "main" { |
| 16 | + t.Errorf("expected 'main', got %s", ref) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// TestParityGitRefEmpty mirrors test: parse_git_reference("") -> (BRANCH, "main") |
| 21 | +func TestParityGitRefEmpty(t *testing.T) { |
| 22 | + refType, ref := dependency.ParseGitReference("") |
| 23 | + if refType != dependency.GitRefBranch { |
| 24 | + t.Errorf("expected BRANCH, got %s", refType) |
| 25 | + } |
| 26 | + if ref != "main" { |
| 27 | + t.Errorf("expected 'main', got %s", ref) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// TestParityGitRefCommitSHA mirrors: parse_git_reference("abc1234") -> (COMMIT, "abc1234") |
| 32 | +func TestParityGitRefCommitSHA(t *testing.T) { |
| 33 | + refType, ref := dependency.ParseGitReference("abc1234") |
| 34 | + if refType != dependency.GitRefCommit { |
| 35 | + t.Errorf("expected COMMIT, got %s", refType) |
| 36 | + } |
| 37 | + if ref != "abc1234" { |
| 38 | + t.Errorf("expected 'abc1234', got %s", ref) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +// TestParityGitRefFullSHA mirrors: full 40-char SHA -> COMMIT |
| 43 | +func TestParityGitRefFullSHA(t *testing.T) { |
| 44 | + sha := "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2" |
| 45 | + refType, ref := dependency.ParseGitReference(sha) |
| 46 | + if refType != dependency.GitRefCommit { |
| 47 | + t.Errorf("expected COMMIT, got %s", refType) |
| 48 | + } |
| 49 | + if ref != sha { |
| 50 | + t.Errorf("expected full SHA, got %s", ref) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +// TestParityGitRefSemver mirrors: "v1.2.3" -> (TAG, "v1.2.3") |
| 55 | +func TestParityGitRefSemver(t *testing.T) { |
| 56 | + refType, ref := dependency.ParseGitReference("v1.2.3") |
| 57 | + if refType != dependency.GitRefTag { |
| 58 | + t.Errorf("expected TAG, got %s", refType) |
| 59 | + } |
| 60 | + if ref != "v1.2.3" { |
| 61 | + t.Errorf("expected 'v1.2.3', got %s", ref) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// TestParityGitRefSemverNoV mirrors: "1.2.3" -> (TAG, "1.2.3") |
| 66 | +func TestParityGitRefSemverNoV(t *testing.T) { |
| 67 | + refType, ref := dependency.ParseGitReference("1.2.3") |
| 68 | + if refType != dependency.GitRefTag { |
| 69 | + t.Errorf("expected TAG, got %s", refType) |
| 70 | + } |
| 71 | + if ref != "1.2.3" { |
| 72 | + t.Errorf("expected '1.2.3', got %s", ref) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +// TestParityGitRefTypeString validates string representations |
| 77 | +func TestParityGitRefTypeString(t *testing.T) { |
| 78 | + cases := []struct { |
| 79 | + refType dependency.GitReferenceType |
| 80 | + want string |
| 81 | + }{ |
| 82 | + {dependency.GitRefBranch, "branch"}, |
| 83 | + {dependency.GitRefTag, "tag"}, |
| 84 | + {dependency.GitRefCommit, "commit"}, |
| 85 | + } |
| 86 | + for _, c := range cases { |
| 87 | + if got := c.refType.String(); got != c.want { |
| 88 | + t.Errorf("GitReferenceType.String() = %s, want %s", got, c.want) |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +// TestParityVirtualPackageTypeString mirrors VirtualPackageType string values |
| 94 | +func TestParityVirtualPackageTypeString(t *testing.T) { |
| 95 | + if dependency.VirtualPackageFile.String() != "file" { |
| 96 | + t.Errorf("expected 'file', got %s", dependency.VirtualPackageFile.String()) |
| 97 | + } |
| 98 | + if dependency.VirtualPackageSubdirectory.String() != "subdirectory" { |
| 99 | + t.Errorf("expected 'subdirectory', got %s", dependency.VirtualPackageSubdirectory.String()) |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// TestParityResolvedReferenceString mirrors ResolvedReference.__str__ |
| 104 | +func TestParityResolvedReferenceString(t *testing.T) { |
| 105 | + // No resolved commit: just refname |
| 106 | + r := dependency.ResolvedReference{RefName: "main", RefType: dependency.GitRefBranch} |
| 107 | + if r.String() != "main" { |
| 108 | + t.Errorf("expected 'main', got %s", r.String()) |
| 109 | + } |
| 110 | + |
| 111 | + // Commit type: short SHA |
| 112 | + r2 := dependency.ResolvedReference{ |
| 113 | + RefType: dependency.GitRefCommit, |
| 114 | + ResolvedCommit: "abc1234def567890", |
| 115 | + RefName: "abc1234", |
| 116 | + } |
| 117 | + if r2.String() != "abc1234d" { |
| 118 | + t.Errorf("expected 'abc1234d', got %s", r2.String()) |
| 119 | + } |
| 120 | + |
| 121 | + // Branch with commit: "main (abc1234de)" |
| 122 | + r3 := dependency.ResolvedReference{ |
| 123 | + RefType: dependency.GitRefBranch, |
| 124 | + RefName: "main", |
| 125 | + ResolvedCommit: "abc1234def567890", |
| 126 | + } |
| 127 | + if r3.String() != "main (abc1234d)" { |
| 128 | + t.Errorf("expected 'main (abc1234d)', got %s", r3.String()) |
| 129 | + } |
| 130 | +} |
0 commit comments