Skip to content

Commit

Permalink
move nomad_scheduler_config data source test to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed May 12, 2021
1 parent 85f5b22 commit 73318c6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
61 changes: 2 additions & 59 deletions nomad/data_source_scheduler_config_test.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,4 @@
package nomad

import (
"testing"

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

func TestAccDataSourceSchedulerConfig_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testProviders,
CheckDestroy: testFinalConfiguration,
Steps: []resource.TestStep{
{
Config: testAccNomadDataSourceSchedulerConfigS,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"scheduler_algorithm",
"spread",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.batch_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.service_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.system_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"memory_oversubscription_enabled",
"true",
),
),
},
},
})
}

const testAccNomadDataSourceSchedulerConfigS = `
resource "nomad_scheduler_config" "config" {
memory_oversubscription_enabled = true
scheduler_algorithm = "spread"
preemption_config = {
system_scheduler_enabled = true
batch_scheduler_enabled = true
service_scheduler_enabled = true
}
}
data "nomad_scheduler_config" "config" {}
`
// The scheduler config needs to be changed sequencially.
// Tests for this data source are defined in resource_scheduler_config_test.go.
44 changes: 44 additions & 0 deletions nomad/resource_scheduler_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ func TestSchedulerConfig_basic(t *testing.T) {
),
),
},
{
Config: testAccNomadSchedulerConfigDataSource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"scheduler_algorithm",
"binpack",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.batch_scheduler_enabled",
"false",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.service_scheduler_enabled",
"true",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"preemption_config.system_scheduler_enabled",
"false",
),
resource.TestCheckResourceAttr(
"data.nomad_scheduler_config.config",
"memory_oversubscription_enabled",
"true",
),
),
},
},
})
}
Expand Down Expand Up @@ -121,6 +151,20 @@ resource "nomad_scheduler_config" "config" {
}
`

const testAccNomadSchedulerConfigDataSource = `
data "nomad_scheduler_config" "config" {}
resource "nomad_scheduler_config" "config" {
memory_oversubscription_enabled = true
scheduler_algorithm = "binpack"
preemption_config = {
system_scheduler_enabled = false
batch_scheduler_enabled = false
service_scheduler_enabled = true
}
}
`

// for details on why this is the way it is, checkout the comments on
// resourceSchedulerConfigurationDelete.
func testFinalConfiguration(_ *terraform.State) error { return nil }

0 comments on commit 73318c6

Please sign in to comment.