|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/ktrysmt/go-bitbucket" |
| 8 | +) |
| 9 | + |
| 10 | +func getClient(t *testing.T) *bitbucket.Client { |
| 11 | + user := os.Getenv("BITBUCKET_TEST_USERNAME") |
| 12 | + pass := os.Getenv("BITBUCKET_TEST_PASSWORD") |
| 13 | + |
| 14 | + if user == "" { |
| 15 | + t.Error("BITBUCKET_TEST_USERNAME is empty.") |
| 16 | + } |
| 17 | + if pass == "" { |
| 18 | + t.Error("BITBUCKET_TEST_PASSWORD is empty.") |
| 19 | + } |
| 20 | + |
| 21 | + return bitbucket.NewBasicAuth(user, pass) |
| 22 | +} |
| 23 | + |
| 24 | +func getOwner(t *testing.T) string { |
| 25 | + owner := os.Getenv("BITBUCKET_TEST_OWNER") |
| 26 | + |
| 27 | + if owner == "" { |
| 28 | + t.Error("BITBUCKET_TEST_OWNER is empty.") |
| 29 | + } |
| 30 | + |
| 31 | + return owner |
| 32 | +} |
| 33 | + |
| 34 | +func TestProjectCreate_isPrivateTrue(t *testing.T) { |
| 35 | + c := getClient(t) |
| 36 | + |
| 37 | + projectName := "go-bitbucket-test-project-create-is-private-true" |
| 38 | + projectKey := "GO_BB_TEST_PROJ_CR_IS_PRIV_TRUE" |
| 39 | + opt := &bitbucket.ProjectOptions{ |
| 40 | + Owner: getOwner(t), |
| 41 | + Name: projectName, |
| 42 | + Key: projectKey, |
| 43 | + IsPrivate: true, |
| 44 | + } |
| 45 | + project, err := c.Workspaces.CreateProject(opt) |
| 46 | + if err != nil { |
| 47 | + t.Error("The project could not be created.") |
| 48 | + } |
| 49 | + |
| 50 | + if project.Name != projectName { |
| 51 | + t.Error("The project `Name` attribute does not match the expected value.") |
| 52 | + } |
| 53 | + if project.Key != projectKey { |
| 54 | + t.Error("The project `Key` attribute does not match the expected value.") |
| 55 | + } |
| 56 | + if project.Is_private != true { |
| 57 | + t.Error("The project `Is_private` attribute does not match the expected value.") |
| 58 | + } |
| 59 | + |
| 60 | + // Delete the project, so we can keep a clean test environment |
| 61 | + _, err = c.Workspaces.DeleteProject(opt) |
| 62 | + if err != nil { |
| 63 | + t.Error(err) |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +func TestProjectCreate_isPrivateFalse(t *testing.T) { |
| 68 | + c := getClient(t) |
| 69 | + |
| 70 | + projectName := "go-bitbucket-test-project-create-is-private-false" |
| 71 | + projectKey := "GO_BB_TEST_PROJ_CR_IS_PRIV_FALSE" |
| 72 | + opt := &bitbucket.ProjectOptions{ |
| 73 | + Owner: getOwner(t), |
| 74 | + Name: projectName, |
| 75 | + Key: projectKey, |
| 76 | + IsPrivate: false, |
| 77 | + } |
| 78 | + project, err := c.Workspaces.CreateProject(opt) |
| 79 | + if err != nil { |
| 80 | + t.Error("The project could not be created.") |
| 81 | + } |
| 82 | + |
| 83 | + if project.Name != projectName { |
| 84 | + t.Error("The project `Name` attribute does not match the expected value.") |
| 85 | + } |
| 86 | + if project.Key != projectKey { |
| 87 | + t.Error("The project `Key` attribute does not match the expected value.") |
| 88 | + } |
| 89 | + if project.Is_private != false { |
| 90 | + t.Error("The project `Is_private` attribute does not match the expected value.") |
| 91 | + } |
| 92 | + |
| 93 | + // Delete the project, so we can keep a clean test environment |
| 94 | + _, err = c.Workspaces.DeleteProject(opt) |
| 95 | + if err != nil { |
| 96 | + t.Error(err) |
| 97 | + } |
| 98 | +} |
0 commit comments