Skip to content

Commit a2f4211

Browse files
committed
Test coverage: getters on internal/pkgmanager/Pkg type
Signed-off-by: Tieg Zaharia <tieg.zaharia@gmail.com>
1 parent 391a204 commit a2f4211

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package pkgmanager
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ossf/package-analysis/pkg/api/pkgecosystem"
7+
)
8+
9+
func TestName(t *testing.T) {
10+
expectedName := "a-package"
11+
p := Pkg{name: expectedName}
12+
13+
actualName := p.Name()
14+
if actualName != expectedName {
15+
t.Errorf("Name() = %v; want %v", actualName, expectedName)
16+
}
17+
}
18+
19+
func TestVersion(t *testing.T) {
20+
expectedVersion := "1.0.0"
21+
p := Pkg{version: expectedVersion}
22+
23+
actualVersion := p.Version()
24+
if actualVersion != expectedVersion {
25+
t.Errorf("Version() = %v; want %v", actualVersion, expectedVersion)
26+
}
27+
}
28+
29+
func TestEcosystem(t *testing.T) {
30+
expectedEcosystem := pkgecosystem.NPM
31+
p := Pkg{manager: &PkgManager{ecosystem: expectedEcosystem}}
32+
33+
actualEcosystem := p.Ecosystem()
34+
if actualEcosystem != expectedEcosystem {
35+
t.Errorf("Ecosystem() = %v; want %v", actualEcosystem, expectedEcosystem)
36+
}
37+
}
38+
39+
func TestEcosystemName(t *testing.T) {
40+
expectedEcosystemName := "npm"
41+
p := Pkg{manager: &PkgManager{ecosystem: pkgecosystem.NPM}}
42+
43+
actualEcosystemName := p.EcosystemName()
44+
if actualEcosystemName != expectedEcosystemName {
45+
t.Errorf("EcosystemName() = %v; want %v", actualEcosystemName, expectedEcosystemName)
46+
}
47+
}
48+
49+
func TestManager(t *testing.T) {
50+
expectedPkgManager := &PkgManager{ecosystem: pkgecosystem.RubyGems}
51+
p := Pkg{manager: expectedPkgManager}
52+
53+
actualPkgManager := p.Manager()
54+
if actualPkgManager != expectedPkgManager {
55+
t.Errorf("Manager() = %v; want %v", actualPkgManager, expectedPkgManager)
56+
}
57+
}
58+
59+
func TestIsLocal(t *testing.T) {
60+
expectedIsLocal := true
61+
p := Pkg{local: "some/local/path"}
62+
63+
actualIsLocal := p.IsLocal()
64+
if actualIsLocal != expectedIsLocal {
65+
t.Errorf("IsLocal() = %v; want %v", actualIsLocal, expectedIsLocal)
66+
}
67+
}
68+
69+
func TestLocalPath(t *testing.T) {
70+
expectedLocalPath := "some/local/path"
71+
p := Pkg{local: expectedLocalPath}
72+
73+
actualLocalPath := p.LocalPath()
74+
if actualLocalPath != expectedLocalPath {
75+
t.Errorf("LocalPath() = %v; want %v", actualLocalPath, expectedLocalPath)
76+
}
77+
}

0 commit comments

Comments
 (0)