testsuite/ui/multinode: add first node test

Change-Id: Ibeaee92e6d1a41e408659a5045f52e1908f73089
This commit is contained in:
Clement Sam 2021-10-07 11:24:48 +00:00
parent 4bbf667ad1
commit 29599dd7cd
7 changed files with 147 additions and 1 deletions

View File

@ -44,6 +44,11 @@ func (system *Multinode) NodeURL() storj.NodeURL {
return storj.NodeURL{ID: system.ID(), Address: system.Addr()}
}
// ConsoleURL returns the console URL.
func (system *Multinode) ConsoleURL() string {
return "http://" + system.Addr()
}
// newMultinodes initializes multinode dashboards.
func (planet *Planet) newMultinodes(ctx context.Context, prefix string, count int) (_ []*Multinode, err error) {
defer mon.Task()(&ctx)(&err)

View File

@ -25,6 +25,7 @@ import (
"storj.io/storj/private/server"
"storj.io/storj/storage/filestore"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/apikeys"
"storj.io/storj/storagenode/bandwidth"
"storj.io/storj/storagenode/collector"
"storj.io/storj/storagenode/console/consoleserver"
@ -47,6 +48,8 @@ type StorageNode struct {
Name string
Config storagenode.Config
*storagenode.Peer
apiKey apikeys.APIKey
}
// Label returns name for debugger.
@ -60,6 +63,11 @@ func (system *StorageNode) NodeURL() storj.NodeURL {
return storj.NodeURL{ID: system.Peer.ID(), Address: system.Peer.Addr()}
}
// APIKey returns the API key of the node.
func (system *StorageNode) APIKey() string {
return system.apiKey.Secret.String()
}
// newStorageNodes initializes storage nodes.
func (planet *Planet) newStorageNodes(ctx context.Context, count int, whitelistedSatellites storj.NodeURLs) (_ []*StorageNode, err error) {
defer mon.Task()(&ctx)(&err)
@ -254,9 +262,18 @@ func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index,
return nil, err
}
planet.databases = append(planet.databases, db)
service := apikeys.NewService(db.APIKeys())
apiKey, err := service.Issue(ctx)
if err != nil {
return nil, errs.New("error while trying to issue new api key: %v", err)
}
return &StorageNode{
Name: prefix,
Config: config,
Peer: peer,
apiKey: apiKey,
}, nil
}

View File

@ -734,4 +734,3 @@ func Schema() map[string]*dbschema.Schema {
"used_serial": &dbschema.Schema{},
}
}

View File

@ -0,0 +1,56 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package multinode
import (
"testing"
"github.com/go-rod/rod"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
"storj.io/storj/testsuite/ui/uitest"
)
func TestAddFirstNodeEmptyInputs(t *testing.T) {
uitest.Multinode(t, 1, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, browser *rod.Browser) {
startPage := planet.Multinodes[0].ConsoleURL() + "/add-first-node"
page := openPage(browser, startPage)
addNodeButton := page.MustElement(".add-first-node__left-area__button")
require.Equal(t, "Add Node", addNodeButton.MustText())
addNodeButton.MustClick()
nodeIDError := page.MustElementX("(//*[@class=\"label-container__main__error\"])[1]").MustText()
require.Equal(t, "This field is required. Please enter a valid node ID", nodeIDError)
ipAddressError := page.MustElementX("(//*[@class=\"label-container__main__error\"])[2]").MustText()
require.Equal(t, "This field is required. Please enter a valid node Public Address", ipAddressError)
apiKeyError := page.MustElementX("(//*[@class=\"label-container__main__error\"])[3]").MustText()
require.Equal(t, "This field is required. Please enter a valid API Key", apiKeyError)
})
}
func TestAddFirstNodeSuccessful(t *testing.T) {
uitest.Multinode(t, 1, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, browser *rod.Browser) {
startPage := planet.Multinodes[0].ConsoleURL() + "/add-first-node"
page := openPage(browser, startPage)
node := planet.StorageNodes[0]
page.MustElement("input#Node\\ ID.headered-input").MustInput(node.ID().String())
page.MustElement("input#Public\\ IP\\ Address.headered-input").MustInput(node.Addr())
page.MustElement("input#API\\ Key.headered-input").MustInput(node.APIKey())
addNodeButton := page.MustElement(".add-first-node__left-area__button")
require.Equal(t, "Add Node", addNodeButton.MustText())
addNodeButton.MustClick()
page.MustWaitNavigation()
nodesPageTitle := page.MustElement("h1.my-nodes__title").MustText()
require.Equal(t, "My Nodes", nodesPageTitle)
})
}

View File

@ -0,0 +1,15 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package multinode
import (
"github.com/go-rod/rod"
)
func openPage(browser *rod.Browser, url string) *rod.Page {
page := browser.MustPage()
page.MustSetViewport(1350, 600, 1, false)
page.MustNavigate(url).MustWaitLoad()
return page
}

View File

@ -0,0 +1,34 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package uitest
import (
"os"
"testing"
"github.com/go-rod/rod"
"storj.io/common/testcontext"
"storj.io/storj/multinode"
"storj.io/storj/private/testplanet"
)
// Multinode starts a new UI test with multinode instance(s).
func Multinode(t *testing.T, multinodeCount int, test Test) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 4, MultinodeCount: multinodeCount,
Reconfigure: testplanet.Reconfigure{
Multinode: func(index int, config *multinode.Config) {
if dir := os.Getenv("STORJ_TEST_MULTINODE_WEB"); dir != "" {
config.Console.StaticDir = dir
}
},
},
NonParallel: true,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
Browser(t, ctx, func(browser *rod.Browser) {
test(t, ctx, planet, browser)
})
})
}

View File

@ -0,0 +1,20 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package uitest_test
import (
"testing"
"github.com/go-rod/rod"
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
"storj.io/storj/testsuite/ui/uitest"
)
func TestMultinode(t *testing.T) {
uitest.Multinode(t, 1, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, browser *rod.Browser) {
t.Log("working")
})
}