Skip to content
6 changes: 4 additions & 2 deletions internal/cli/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

type Provider int

type Timestamp int64

const (
ProviderMiner Provider = iota + 1
ProviderSharder
Expand Down Expand Up @@ -111,8 +113,8 @@ type ListFileResult struct {
EncryptionKey string `json:"encryption_key"`
ActualSize int64 `json:"actual_size"`
ActualNumBlocks int `json:"actual_num_blocks"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt Timestamp `json:"created_at"`
UpdatedAt Timestamp `json:"updated_at"`
}

type Terms struct {
Expand Down
46 changes: 10 additions & 36 deletions tests/cli_tests/zboxcli_create_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func TestCreateDir(t *testing.T) {
output, err := createDir(t, configPath, allocID, longDirName, false)
require.NotNil(t, err, "expected create dir failure command executed with output: ", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.True(t, strings.HasPrefix(output[0], `CreateDir failed: {"error":"ERROR: value too long for type character varying(100) (SQLSTATE 22001)"}`), "expected create dir failure command executed with output: ", strings.Join(output, "\n"))
aggregatedOutput := strings.ToLower(strings.Join(output, " "))
require.Contains(t, aggregatedOutput, "directory creation failed")
require.Contains(t, aggregatedOutput, "consensus not met")

output, err = listAll(t, configPath, allocID, true)
require.Nil(t, err, "Unexpected list all failure %s", strings.Join(output, "\n"))
Expand Down Expand Up @@ -140,45 +142,16 @@ func TestCreateDir(t *testing.T) {
require.Equal(t, dirname+" directory created", output[0])
})

t.Run("create dir with no leading slash should work", func(t *testing.T) {
t.Run("create dir with no leading slash should not work", func(t *testing.T) {
t.Parallel()

allocID := setupAllocation(t, configPath)

dirname := "noleadingslash"
output, err := createDir(t, configPath, allocID, dirname, true)
require.Nil(t, err, "Unexpected create dir failure %s", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, dirname+" directory created", output[0])

output, err = listAll(t, configPath, allocID, true)
require.Nil(t, err, "Unexpected list all failure %s", strings.Join(output, "\n"))
require.Len(t, output, 1)

var files []climodel.AllocationFile
err = json.Unmarshal([]byte(output[0]), &files)
require.Nil(t, err, "Error deserializing JSON string `%s`: %v", strings.Join(output, "\n"), err)

require.Len(t, files, 1)
require.Equal(t, dirname, files[0].Name, "Directory must be created", files)
})

t.Run("create dir with no leading slash should work", func(t *testing.T) {
t.Parallel()

allocID := setupAllocation(t, configPath)

dirname := "/noleadingslash"
output, err := createDir(t, configPath, allocID, dirname, true)
require.Nil(t, err, "Unexpected create dir failure %s", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, dirname+" directory created", output[0])

dirname = "noleadingslash"
output, err = createDir(t, configPath, allocID, dirname, false)
require.Nil(t, err, "Unexpected create dir failure %s", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.Equal(t, dirname+" directory created", output[0])
output, err := createDir(t, configPath, allocID, dirname, false)
require.Error(t, err)
aggregatedOutput := strings.Join(output, " ")
require.Contains(t, aggregatedOutput, "not absolute")
})

t.Run("create with existing dir but different case", func(t *testing.T) {
Expand Down Expand Up @@ -349,7 +322,8 @@ func TestCreateDir(t *testing.T) {
output, err = createDirForWallet(t, configPath, nonAllocOwnerWallet, true, allocID, true, "/mydir", false)
require.NotNil(t, err, "Expected create dir failure but got output: ", strings.Join(output, "\n"))
require.Len(t, output, 1)
require.True(t, strings.HasPrefix(output[0], `CreateDir failed: {"code":"invalid_signature","error":"invalid_signature: Invalid signature"}`), "Expected create dir failure but got output: "+strings.Join(output, "\n"))
aggregatedOutput := strings.Join(output, " ")
require.Contains(t, aggregatedOutput, `consensus not met`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

})
}

Expand Down