Repository: rclone/rclone
File: fs/operations/rc_test.go (Go)

Code before:
	})

	t.Run("Subdir", func(t *testing.T) {
		stat := fetch(t, "subdir")
		assert.Equal(t, "subdir", stat.Path)
		assert.Equal(t, "subdir", stat.Name)
		assert.Equal(t, int64(-1), stat.Size)
		assert.Equal(t, "inode/directory", stat.MimeType)
		assert.Equal(t, true, stat.IsDir)
	})

	t.Run("NotFound", func(t *testing.T) {
		stat := fetch(t, "notfound")
		assert.Nil(t, stat)
	})
}

// operations/settier: Set the storage tier of a file
func TestRcSettier(t *testing.T) {
	// ctx := context.Background()
	r, call := rcNewRun(t, "operations/settier")
	file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1)
	r.CheckRemoteItems(t, file1)

	if r.Fremote.Features().SetTier {
		in := rc.Params{
			"fs":     r.FremoteName,
			"remote": "file1",
			"tier":   "Cold",
		}
		out, err := call.Fn(context.Background(), in)
		require.NoError(t, err)
		assert.Equal(t, rc.Params(nil), out)
	}

}

// operations/mkdir: Make a destination directory or container
func TestRcMkdir(t *testing.T) {
	ctx := context.Background()
	r, call := rcNewRun(t, "operations/mkdir")
	r.Mkdir(context.Background(), r.Fremote)

	fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{}, []string{}, fs.GetModifyWindow(ctx, r.Fremote))

	in := rc.Params{
		"fs":     r.FremoteName,
		"remote": "subdir",
	}
	out, err := call.Fn(context.Background(), in)
	require.NoError(t, err)

Review comment (suggestion):
Getting this test right is tricky because we don't know the valid values for tiers.

I think I would get an object with `o, err = f.NewObject(ctx, file1.Path)` read the tier from that by using a type assertion `o.(fs.GetTierer)` and then calling `GetTier()` to read the current tier.

I'd then set the object to its current tier.



Code after:
	})

	t.Run("Subdir", func(t *testing.T) {
		stat := fetch(t, "subdir")
		assert.Equal(t, "subdir", stat.Path)
		assert.Equal(t, "subdir", stat.Name)
		assert.Equal(t, int64(-1), stat.Size)
		assert.Equal(t, "inode/directory", stat.MimeType)
		assert.Equal(t, true, stat.IsDir)
	})

	t.Run("NotFound", func(t *testing.T) {
		stat := fetch(t, "notfound")
		assert.Nil(t, stat)
	})
}

// operations/settier: Set the storage tier of a fs
func TestRcSetTier(t *testing.T) {
	ctx := context.Background()
	r, call := rcNewRun(t, "operations/settier")
	if !r.Fremote.Features().SetTier {
		t.Skip("settier not supported")
	}
	file1 := r.WriteObject(context.Background(), "file1", "file1 contents", t1)
	r.CheckRemoteItems(t, file1)

	// Because we don't know what the current tier options here are, let's
	// just get the current tier, and re-use that
	o, err := r.Fremote.NewObject(ctx, file1.Path)
	require.NoError(t, err)
	trr, ok := o.(fs.GetTierer)
	require.True(t, ok)
	ctier := trr.GetTier()
	in := rc.Params{
		"fs":   r.FremoteName,
		"tier": ctier,
	}
	out, err := call.Fn(context.Background(), in)
	require.NoError(t, err)
	assert.Equal(t, rc.Params(nil), out)

}

// operations/settier: Set the storage tier of a file
func TestRcSetTierFile(t *testing.T) {
	ctx := context.Background()
	r, call := rcNewRun(t, "operations/settierfile")
	if !r.Fremote.Features().SetTier {
		t.Skip("settier not supported")
	}