storj/satellite/satellitedb/buckets_test.go
aligeti daa3b32ee2
Add Attribution Columns to appropriate tables for OSPP referral link (#2516)
* adds "partner_id" column to user, project, api_key & bucket_metainfo tables
2019-07-12 13:59:19 -04:00

93 lines
2.4 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package satellitedb_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testrand"
"storj.io/storj/pkg/storj"
"storj.io/storj/satellite"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestUsers(t *testing.T) {
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
consoleDB := db.Console()
// create user
userPassHash := testrand.Bytes(8)
// create an user with partnerID
_, err := consoleDB.Users().Insert(ctx, &console.User{
FullName: "John Doe",
Email: "john@mail.test",
PasswordHash: userPassHash,
Status: console.Active,
PartnerID: testrand.UUID(),
})
require.NoError(t, err)
// create an user with no partnerID
_, err = consoleDB.Users().Insert(ctx, &console.User{
FullName: "John Doe",
Email: "john@mail.test",
PasswordHash: userPassHash,
Status: console.Active,
})
require.NoError(t, err)
// create a project with partnerID
_, err = consoleDB.Projects().Insert(ctx, &console.Project{
ID: testrand.UUID(),
Name: "John Doe",
Description: "some description",
UsageLimit: int64(1000),
PartnerID: testrand.UUID(),
CreatedAt: time.Now(),
})
require.NoError(t, err)
// create a project with no partnerID
proj, err := consoleDB.Projects().Insert(ctx, &console.Project{
ID: testrand.UUID(),
Name: "John Doe",
Description: "some description",
UsageLimit: int64(1000),
PartnerID: testrand.UUID(),
CreatedAt: time.Now(),
})
require.NoError(t, err)
// create a APIKey with no partnerID
_, err = consoleDB.APIKeys().Create(ctx, testrand.Bytes(8), console.APIKeyInfo{
ID: testrand.UUID(),
ProjectID: proj.ID,
Name: "John Doe",
Secret: []byte("xyz"),
CreatedAt: time.Now(),
})
require.NoError(t, err)
// create a bucket with no partnerID
_, err = db.Buckets().CreateBucket(ctx, storj.Bucket{
ID: testrand.UUID(),
Name: "testbucket",
ProjectID: proj.ID,
Created: time.Now(),
PathCipher: storj.EncAESGCM,
DefaultSegmentsSize: int64(100),
})
require.NoError(t, err)
})
}