|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/ktrysmt/go-bitbucket" |
| 8 | +) |
| 9 | + |
| 10 | +func TestListForAccount(t *testing.T) { |
| 11 | + user := os.Getenv("BITBUCKET_TEST_USERNAME") |
| 12 | + pass := os.Getenv("BITBUCKET_TEST_PASSWORD") |
| 13 | + owner := os.Getenv("BITBUCKET_TEST_OWNER") |
| 14 | + repo := os.Getenv("BITBUCKET_TEST_REPOSLUG") |
| 15 | + |
| 16 | + if user == "" { |
| 17 | + t.Error("BITBUCKET_TEST_USERNAME is empty.") |
| 18 | + } |
| 19 | + if pass == "" { |
| 20 | + t.Error("BITBUCKET_TEST_PASSWORD is empty.") |
| 21 | + } |
| 22 | + if owner == "" { |
| 23 | + t.Error("BITBUCKET_TEST_OWNER is empty.") |
| 24 | + } |
| 25 | + if repo == "" { |
| 26 | + t.Error("BITBUCKET_TEST_REPOSLUG is empty.") |
| 27 | + } |
| 28 | + |
| 29 | + c := bitbucket.NewBasicAuth(user, pass) |
| 30 | + |
| 31 | + repositories, err := c.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{ |
| 32 | + Owner: owner, |
| 33 | + }) |
| 34 | + if err != nil { |
| 35 | + t.Error("Unable to fetch repositories") |
| 36 | + } |
| 37 | + |
| 38 | + found := false |
| 39 | + for _, r := range repositories.Items { |
| 40 | + if r.Slug == repo { |
| 41 | + found = true |
| 42 | + break |
| 43 | + } |
| 44 | + } |
| 45 | + if !found { |
| 46 | + t.Error("Did not find repository in list") |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestListForTeam(t *testing.T) { |
| 51 | + user := os.Getenv("BITBUCKET_TEST_USERNAME") |
| 52 | + pass := os.Getenv("BITBUCKET_TEST_PASSWORD") |
| 53 | + owner := os.Getenv("BITBUCKET_TEST_OWNER") |
| 54 | + repo := os.Getenv("BITBUCKET_TEST_REPOSLUG") |
| 55 | + |
| 56 | + if user == "" { |
| 57 | + t.Error("BITBUCKET_TEST_USERNAME is empty.") |
| 58 | + } |
| 59 | + if pass == "" { |
| 60 | + t.Error("BITBUCKET_TEST_PASSWORD is empty.") |
| 61 | + } |
| 62 | + if owner == "" { |
| 63 | + t.Error("BITBUCKET_TEST_OWNER is empty.") |
| 64 | + } |
| 65 | + if repo == "" { |
| 66 | + t.Error("BITBUCKET_TEST_REPOSLUG is empty.") |
| 67 | + } |
| 68 | + |
| 69 | + c := bitbucket.NewBasicAuth(user, pass) |
| 70 | + |
| 71 | + //goland:noinspection GoDeprecation |
| 72 | + repositories, err := c.Repositories.ListForTeam(&bitbucket.RepositoriesOptions{ |
| 73 | + |
| 74 | + Owner: owner, |
| 75 | + }) |
| 76 | + if err != nil { |
| 77 | + t.Error("Unable to fetch repositories") |
| 78 | + } |
| 79 | + |
| 80 | + found := false |
| 81 | + for _, r := range repositories.Items { |
| 82 | + if r.Slug == repo { |
| 83 | + found = true |
| 84 | + break |
| 85 | + } |
| 86 | + } |
| 87 | + if !found { |
| 88 | + t.Error("Did not find repository in list") |
| 89 | + } |
| 90 | +} |
0 commit comments