kubernetes/pkg/cloudprovider/providers/vsphere/vclib/datastore_test.go
Doug MacEachern 64601373f1 vsphere: use vim25.Client directly to support token authentication
This refactor is in support of SAML token authentication: #63209
Avoid use of govmomi.Client as it only supports username+password authentication via SessionManager.Login().
Using vim25.Client directly will allow VCP to add other authentication methods,
such as SessionManager.LoginByToken().
2018-05-07 08:50:31 -07:00

92 lines
1.9 KiB
Go

/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vclib
import (
"context"
"testing"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator"
)
func TestDatastore(t *testing.T) {
ctx := context.Background()
// vCenter model + initial set of objects (cluster, hosts, VMs, network, datastore, etc)
model := simulator.VPX()
defer model.Remove()
err := model.Create()
if err != nil {
t.Fatal(err)
}
s := model.Service.NewServer()
defer s.Close()
c, err := govmomi.NewClient(ctx, s.URL, true)
if err != nil {
t.Fatal(err)
}
vc := &VSphereConnection{GoVmomiClient: c.Client}
dc, err := GetDatacenter(ctx, vc, testDefaultDatacenter)
if err != nil {
t.Error(err)
}
all, err := dc.GetAllDatastores(ctx)
if err != nil {
t.Fatal(err)
}
for _, info := range all {
ds := info.Datastore
kind, cerr := ds.GetType(ctx)
if cerr != nil {
t.Error(err)
}
if kind == "" {
t.Error("empty Datastore type")
}
dir := object.DatastorePath{
Datastore: info.Info.Name,
Path: "kubevols",
}
// TODO: test Datastore.IsCompatibleWithStoragePolicy (vcsim needs PBM support)
for _, fail := range []bool{false, true} {
cerr = ds.CreateDirectory(ctx, dir.String(), false)
if fail {
if cerr != ErrFileAlreadyExist {
t.Errorf("expected %s, got: %s", ErrFileAlreadyExist, cerr)
}
continue
}
if cerr != nil {
t.Error(err)
}
}
}
}