Skip to content

Commit

Permalink
fix: fly volume fork --require-unique-zone should be default (#3955)
Browse files Browse the repository at this point in the history
Checking `flag.IsSpecified` makes its default false.
  • Loading branch information
kzys authored Sep 20, 2024
1 parent f086b4f commit f9a14b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 1 addition & 6 deletions internal/command/volumes/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ func runFork(ctx context.Context) error {
machinesOnly = fly.Pointer(flag.GetBool(ctx, "machines-only"))
}

var requireUniqueZone *bool
if flag.IsSpecified(ctx, "require-unique-zone") {
requireUniqueZone = fly.Pointer(flag.GetBool(ctx, "require-unique-zone"))
}

region := flag.GetString(ctx, "region")

var attachedMachineImage string
Expand All @@ -131,7 +126,7 @@ func runFork(ctx context.Context) error {
input := fly.CreateVolumeRequest{
Name: name,
MachinesOnly: machinesOnly,
RequireUniqueZone: requireUniqueZone,
RequireUniqueZone: fly.Pointer(flag.GetBool(ctx, "require-unique-zone")),
SourceVolumeID: &vol.ID,
ComputeRequirements: computeRequirements,
ComputeImage: attachedMachineImage,
Expand Down
16 changes: 16 additions & 0 deletions test/preflight/fly_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestVolume(t *testing.T) {
t.Run("Extend", WithParallel(testVolumeExtend))
t.Run("List", WithParallel(testVolumeLs))
t.Run("CreateFromDestroyedVolSnapshot", WithParallel(testVolumeCreateFromDestroyedVolSnapshot))
t.Run("Fork", WithParallel(testVolumeFork))
}

func testVolumeExtend(t *testing.T) {
Expand Down Expand Up @@ -122,6 +123,21 @@ func testVolumeLs(t *testing.T) {
}, 5*time.Minute, 10*time.Second)
}

func testVolumeFork(t *testing.T) {
f := testlib.NewTestEnvFromEnv(t)
appName := f.CreateRandomAppMachines()

var original *fly.Volume
j := f.Fly("vol create --json --app %s --region %s --yes foobar", appName, f.PrimaryRegion())
j.StdOutJSON(&original)

var fork *fly.Volume
j = f.Fly("vol fork --json --app %s --region %s %s", appName, f.PrimaryRegion(), original.ID)
j.StdOutJSON(&fork)

assert.NotEqual(t, original.Zone, fork.Zone, "forked volume should be in a different zone")
}

func testVolumeCreateFromDestroyedVolSnapshot(tt *testing.T) {
t := testLogger{tt}

Expand Down

0 comments on commit f9a14b8

Please sign in to comment.