Skip to content

Commit

Permalink
csi: rework tests exercising CSI plugin lifecycle state
Browse files Browse the repository at this point in the history
The existing CSI tests for the state store incorrectly modeled the
updates we received from servers vs those we received from clients,
leading to test assertions that passed when they should not.

Rework the tests to clarify each step in the lifecycle.
  • Loading branch information
tgross committed Feb 8, 2022
1 parent 84810dc commit 127a824
Show file tree
Hide file tree
Showing 2 changed files with 354 additions and 598 deletions.
33 changes: 33 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,39 @@ func CSIVolume(plugin *structs.CSIPlugin) *structs.CSIVolume {
}
}

func CSIPluginJob(pluginType structs.CSIPluginType, pluginID string) *structs.Job {

job := new(structs.Job)

switch pluginType {
case structs.CSIPluginTypeController:
job = Job()
job.ID = fmt.Sprintf("mock-controller-%s", pluginID)
job.Name = "job-plugin-controller"
job.TaskGroups[0].Count = 2
case structs.CSIPluginTypeNode:
job = SystemJob()
job.ID = fmt.Sprintf("mock-node-%s", pluginID)
job.Name = "job-plugin-node"
case structs.CSIPluginTypeMonolith:
job = SystemJob()
job.ID = fmt.Sprintf("mock-monolith-%s", pluginID)
job.Name = "job-plugin-monolith"
}

job.TaskGroups[0].Name = "plugin"
job.TaskGroups[0].Tasks[0].Name = "plugin"
job.TaskGroups[0].Tasks[0].Driver = "docker"
job.TaskGroups[0].Tasks[0].Services = nil
job.TaskGroups[0].Tasks[0].CSIPluginConfig = &structs.TaskCSIPluginConfig{
ID: pluginID,
Type: pluginType,
MountDir: "/csi",
}
job.Canonicalize()
return job
}

func Events(index uint64) *structs.Events {
return &structs.Events{
Index: index,
Expand Down
Loading

0 comments on commit 127a824

Please sign in to comment.