This repository was archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
54 lines (49 loc) · 1.34 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"testing"
)
func TestGithubExtractUsernameAndRepository(t *testing.T) {
imp := "github.com/username/repo/path"
username, repo, err := extractUsernameAndRepository(imp)
if err != nil {
t.Error("Should return username and repo but returned error")
}
if username != "username" {
t.Error("Should return username but returned", username)
}
if repo != "repo" {
t.Error("Should return repo but returned", repo)
}
}
func TestIsGitgubPackage(t *testing.T) {
if isGithubPackage("github.com/foo/bar") == false {
t.Error("Should be true")
}
if isGithubPackage("foohub.com/foo/bar") == true {
t.Error("Should be false")
}
}
func TestNewGithubPackage(t *testing.T) {
pkg, err := newGithubPackage("github.com/foo/bar", "")
if err != nil {
t.Fatal("Should not return error")
}
if pkg.username != "foo" {
t.Error("Expected foo, got", pkg.username)
}
if pkg.repository != "bar" {
t.Error("Expected bar, got", pkg.repository)
}
}
func TestAddUniquePackage(t *testing.T) {
var packages = make(packagesList, 0)
pkg1, _ := newGithubPackage("github.com/foo1/bar1", "")
pkg2, _ := newGithubPackage("github.com/foo2/bar2", "")
pkg3, _ := newGithubPackage("github.com/foo2/bar2", "")
packages.Add(pkg1)
packages.Add(pkg2)
packages.Add(pkg3)
if packages.Count() != 2 {
t.Error("Expected 2 packages, got", packages.Count())
}
}