Skip to content

Commit

Permalink
separating files
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsz-rb committed Feb 28, 2024
1 parent aa38191 commit 0584102
Show file tree
Hide file tree
Showing 16 changed files with 3,637 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ test:
@#echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc:
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage_client.out github.com/rollbar/terraform-provider-rollbar/client -v $(TESTARGS) -timeout 10m
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage_project.out github.com/rollbar/terraform-provider-rollbar/rollbar -v $(TESTARGS) -timeout 10m -testify.m ^TestAccProject
cat coverage_client.out coverage_project.out > coverage.out
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage.out $(TEST) -v $(TESTARGS) -timeout 120m
slscan:
./.slscan.sh

Expand Down
72 changes: 72 additions & 0 deletions rollbar/test1/data_source_project_access_token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2020 Rollbar, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package test1

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// TestAccProjectAccessTokenDataSource tests reading a project access token with
// `rollbar_project_access_token` data source.
func (s *AccSuite) TestAccProjectAccessTokenDataSource() {
rn := "data.rollbar_project_access_token.test"
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
resource "rollbar_project_access_token" "test" {
name = "test-token"
project_id = rollbar_project.test.id
scopes = ["read"]
}
data "rollbar_project_access_token" "test" {
project_id = rollbar_project.test.id
name = "test-token"
depends_on = [rollbar_project_access_token.test]
}
`
config := fmt.Sprintf(tmpl, s.randName)
resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
s.checkResourceStateSanity(rn),
resource.TestCheckResourceAttrSet(rn, "access_token"),
resource.TestCheckResourceAttrSet(rn, "project_id"),
resource.TestCheckResourceAttrSet(rn, "date_created"),
resource.TestCheckResourceAttrSet(rn, "date_modified"),
resource.TestCheckResourceAttr(rn, "name", "test-token"),
),
},
},
})
}
197 changes: 197 additions & 0 deletions rollbar/test1/data_source_project_access_tokens_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Copyright (c) 2020 Rollbar, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package test1

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// TestAccProjectAccessTokensDataSourceNoTokensNoPrefix tests reading project
// access tokens with `rollbar_project_access_tokens` data source, with no
// prefix specified, from a project with zero tokens.
func (s *AccSuite) TestAccProjectAccessTokensDataSourceNoTokensNoPrefix() {
rn := "data.rollbar_project_access_tokens.test"
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
data "rollbar_project_access_tokens" "test" {
project_id = rollbar_project.test.id
depends_on = [rollbar_project.test]
}
`
config := fmt.Sprintf(tmpl, s.randName)
resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(rn, "project_id"),
s.checkResourceStateSanity(rn),
resource.TestCheckResourceAttr(rn, "access_tokens.#", "0"),
),
},
},
})
}

// TestAccProjectAccessTokensDataSourceTwoTokensNoPrefix tests reading project
// access tokens with `rollbar_project_access_tokens` data source, with no
// prefix specified, from a project with two tokens.
func (s *AccSuite) TestAccProjectAccessTokensDataSourceTwoTokensNoPrefix() {
rn := "data.rollbar_project_access_tokens.test"
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
resource "rollbar_project_access_token" "test1" {
name = "test-token-1"
project_id = rollbar_project.test.id
scopes = ["read"]
}
resource "rollbar_project_access_token" "test2" {
name = "test-token-2"
project_id = rollbar_project.test.id
scopes = ["post_server_item"]
}
data "rollbar_project_access_tokens" "test" {
project_id = rollbar_project.test.id
depends_on = [
rollbar_project_access_token.test1,
rollbar_project_access_token.test2,
]
}
`
config := fmt.Sprintf(tmpl, s.randName)
resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(rn, "project_id"),
s.checkResourceStateSanity(rn),
resource.TestCheckResourceAttr(rn, "access_tokens.#", "2"),
),
},
},
})
}

// TestAccProjectAccessTokensDataSourceNoTokensWithPrefix tests reading project
// access tokens with `rollbar_project_access_tokens` data source, with a prefix
// specified, from a project with zero tokens.
func (s *AccSuite) TestAccProjectAccessTokensDataSourceNoTokensWithPrefix() {
rn := "data.rollbar_project_access_tokens.test"
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
data "rollbar_project_access_tokens" "test" {
project_id = rollbar_project.test.id
#depends_on = [rollbar_project.test]
prefix = "test-"
}
`
config := fmt.Sprintf(tmpl, s.randName)
resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(rn, "project_id"),
s.checkResourceStateSanity(rn),
resource.TestCheckResourceAttr(rn, "access_tokens.#", "0"),
),
},
},
})
}

// TestAccProjectAccessTokensDataSourceWithTokensWithPrefix tests reading
// project access tokens with `rollbar_project_access_tokens` data source from a
// project with two tokens, with a prefix matching one of those tokens.
func (s *AccSuite) TestAccProjectAccessTokensDataSourceWithTokensWithPrefix() {
rn := "data.rollbar_project_access_tokens.test"
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
resource "rollbar_project_access_token" "test1" {
name = "foo-token"
project_id = rollbar_project.test.id
scopes = ["read"]
}
resource "rollbar_project_access_token" "test2" {
name = "bar-token"
project_id = rollbar_project.test.id
scopes = ["post_server_item"]
}
data "rollbar_project_access_tokens" "test" {
project_id = rollbar_project.test.id
prefix = "foo"
depends_on = [
rollbar_project_access_token.test1,
rollbar_project_access_token.test2,
]
}
`
config := fmt.Sprintf(tmpl, s.randName)
resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(rn, "project_id"),
s.checkResourceStateSanity(rn),
resource.TestCheckResourceAttr(rn, "access_tokens.#", "1"),
),
},
},
})
}
91 changes: 91 additions & 0 deletions rollbar/test1/data_source_project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2020 Rollbar, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package test1

import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/rs/zerolog/log"
)

// TestAccProjectDataSource tests reading a project with `rollbar_project` data
// source.
func (s *AccSuite) TestAccProjectDataSource() {
rn := "data.rollbar_project.test"

resource.ParallelTest(s.T(), resource.TestCase{
PreCheck: func() { s.preCheck() },
Providers: s.providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
PreConfig: func() {
log.Debug().Msg("Testing data source rollbar_project with invalid project name")
},
Config: s.configDataSourceProjectNotFound(),
ExpectError: regexp.MustCompile("no project with the name"),
},
{
PreConfig: func() {
log.Debug().Msg("Testing data source rollbar_project")
},
Config: s.configDataSourceProject(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(rn, "name", s.randName),
resource.TestCheckResourceAttrSet(rn, "id"),
resource.TestCheckResourceAttrSet(rn, "account_id"),
resource.TestCheckResourceAttrSet(rn, "date_created"),
resource.TestCheckResourceAttrSet(rn, "date_modified"),
resource.TestCheckResourceAttr(rn, "status", "enabled"),
),
},
},
})
}

func (s *AccSuite) configDataSourceProject() string {
// language=hcl
tmpl := `
resource "rollbar_project" "test" {
name = "%s"
}
data "rollbar_project" "test" {
name = "%s"
depends_on = [rollbar_project.test]
}
`
return fmt.Sprintf(tmpl, s.randName, s.randName)
}

func (s *AccSuite) configDataSourceProjectNotFound() string {
// language=hcl
tmpl := `
data "rollbar_project" "test" {
name = "%s"
}
`
return fmt.Sprintf(tmpl, s.randName)
}
Loading

0 comments on commit 0584102

Please sign in to comment.