testutil

package
v0.0.0-...-1643d90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2020 License: UPL-1.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PMS_ENDPOINT    = "PMS_ENDPOINT"    //policy management endpoint
	ADS_ENDPOINT    = "ADS_ENDPOINT"    //authorization check endpoint
	PMS_ADMIN_TOKEN = "PMS_ADMIN_TOKEN" //token when do policy management
	ADS_ADMIN_TOKEN = "ADS_ADMIN_TOKEN" //token when do authorization check
	CA_LOCATION     = "CA_LOCATION"     //CA file absoulute location
	CERT_LOCATION   = "CERT_LOCATION"   //CERT file absoulute location
	KEY_LOCATION    = "KEY_LOCATION"    //public key file location
)
View Source
const (
	URI_POLICY_MGMT   = svcs.PolicyMgmtPath
	URI_IS_ALLOWD     = svcs.PolicyAtzPath + "is-allowed"
	URI_GRANTED_ROLES = svcs.PolicyAtzPath + "all-granted-roles"
	URI_GRANTED_PERMS = svcs.PolicyAtzPath + "all-granted-permissions"

	WAIT_POLICY_Initialize = 500 //ms
)
View Source
const (
	METHOD_CREATE_SERVICE          = "createService"
	METHOD_GET_SERVICE             = "getService" //not used in grpc
	METHOD_QUERY_SERVICE           = "queryService"
	METHOD_DELETE_SERVICE          = "deleteService"
	METHOD_CREATE_POLICY           = "createPolicy"
	METHOD_GET_POLICY              = "getPolicy" //not used in grpc
	METHOD_QUERY_POLICY            = "queryPolicy"
	METHOD_DELETE_POLICY           = "deletePolicy"
	METHOD_CREATE_ROLEPOLICY       = "createRolePolicy"
	METHOD_GET_ROLEPOLICY          = "getRolePolicy" //not used in grpc
	METHOD_QUERY_ROLEPOLICY        = "queryRolePolicy"
	METHOD_DELETE_ROLEPOLICY       = "deleteRolePolicy"
	METHOD_IS_ALLOWED              = "isAllowed"
	METHOD_GET_GRANTED_PERMISSIONS = "getPerssions"
	METHOD_GET_GRANTED_ROLES       = "getRoles"
	METHOD_SLEEP                   = "sleep"
)

Test Methods for Speedle

View Source
const (
	ERROR_SPEEDLE_NOT_SUPPORTED = "speedle doesn't support"
)
View Source
const (
	METHOD_CONFIG = "config"
)

Test Methods for Speedle

View Source
const (
	SP_APP_NAME = "SP_APP_NAME"
)

Variables

View Source
var SpecialNames []string
View Source
var TestLog *testing.T

Functions

func CompareStringArray_NoOrder

func CompareStringArray_NoOrder(strArray1 []string, strArray2 []string) bool

CompareStringArray_NoOrder check two string arrays containing same elements ignoring the order

func GenerateJsonFileWithPolicy

func GenerateJsonFileWithPolicy(fileNameWithPath string, policy *pmsapi.Policy)

generate a json file according to policy object

func GenerateJsonFileWithRolePolicy

func GenerateJsonFileWithRolePolicy(fileNameWithPath string, service *pmsapi.RolePolicy)

generate a json file according to role policy object

func GenerateJsonFileWithService

func GenerateJsonFileWithService(fileNameWithPath string, service *pmsapi.Service)

generate a json file according to service object

func GeneratePdlFile

func GeneratePdlFile(fileNameWithPath string, pdlList []string)

generate a file according to pdl list

func GetOSEnv

func GetOSEnv(name string, defaultValue string) string

Get OS environment, if not exists, return the default Value

func InitSpecialNames

func InitSpecialNames()

func PostCreateGetPolicyTest

func PostCreateGetPolicyTest(data interface{}, context *TestContext)

*

Function called after create/get policy test
Modify the ID in outputBody and expected body

*

func PostCreateGetRolePolicyTest

func PostCreateGetRolePolicyTest(data interface{}, context *TestContext)

*

Function called after create/get role policy test
Modify the ID in outputBody and expected body

*

func PostCreateGetServiceTest

func PostCreateGetServiceTest(data interface{}, context *TestContext)

*

Function called after Create or Get service test
Modify the ID in outputBody and expected body

*

func PostGetAllGrantedPermissions

func PostGetAllGrantedPermissions(data interface{}, context *TestContext)

Sort the output by resource name string

func PostGetAllGrantedRoles

func PostGetAllGrantedRoles(data interface{}, context *TestContext)

Sort the output by role name string

func PostListPolicyTest

func PostListPolicyTest(data interface{}, context *TestContext)

func PostListRolePolicyTest

func PostListRolePolicyTest(data interface{}, context *TestContext)

*

Function called after List role  policy test
Modify the ID in outputBody and expected body

*

func PostListServiceTest

func PostListServiceTest(data interface{}, context *TestContext)

*

Function called after listing service test
Modify the ID in outputBody and expected body

*

func PreGetDeletePolicyTest

func PreGetDeletePolicyTest(data interface{}, context *TestContext)

Function called before Get/Delete policy/rolepolicy Update the policy/rolepolicy name with ID in the request since we only support get/delete with ID

func RunTestCases

func RunTestCases(t *testing.T, testcases *[]TestCase, ctx *TestContext)

Run a group of Test cases

func SetOSEnv

func SetOSEnv(name string, value string) error

Set OS environment

func VerifyCmdTestByDefault

func VerifyCmdTestByDefault(data interface{}, context *TestContext) bool

Verify CmdTestData By Default

func VerifyGRpcAllGrantedPermissions

func VerifyGRpcAllGrantedPermissions(data interface{}, context *TestContext) bool

VerifyGRpcAllGrantedPermissions verify allGrantedPermissions response

func VerifyGRpcAllGrantedRoleResult

func VerifyGRpcAllGrantedRoleResult(data interface{}, context *TestContext) bool

Verify RestTestData By Default

func VerifyGRpcTestByDefault

func VerifyGRpcTestByDefault(data interface{}, context *TestContext) bool

Verify RestTestData By Default

func VerifyRestTestByDefault

func VerifyRestTestByDefault(data interface{}, context *TestContext) bool

Verify RestTestData By Default

Types

type Cmd

type Cmd struct {
	// contains filtered or unexported fields
}

Class for exec.Cmd, standard output & error message & execute error

func Command

func Command(name string, arg ...string) *Cmd

Constructor for Cmd class

func (*Cmd) Run

func (c *Cmd) Run()

execute the command.

func (*Cmd) Stderr

func (c *Cmd) Stderr() string

Gget the Stderr of exec.Cmd

func (*Cmd) Stdout

func (c *Cmd) Stdout() string

Get the Stdout of exec.Cmd

func (*Cmd) Success

func (c *Cmd) Success() bool

Return true if command run successfully Otherwise, return false

type CmdClient

type CmdClient struct {
	// contains filtered or unexported fields
}

func NewCmdClient

func NewCmdClient() *CmdClient

Get the test client for Cmd

func NewCmdClient_token

func NewCmdClient_token(token string) *CmdClient

Get the test client for Cmd

func (*CmdClient) CreateServiceWithPDL

func (client *CmdClient) CreateServiceWithPDL(serviceName string, pdl []string) bool

Create service with PDL file

func (*CmdClient) ExecuteCmd

func (client *CmdClient) ExecuteCmd(parameter string, data *CmdTestData) error

execute spxctl command with specified parameter and test data

type CmdTest

type CmdTest struct {
	Client *CmdClient
}

func (*CmdTest) Execute

func (test *CmdTest) Execute(testcase *TestCase, ctx *TestContext) error

Execute current test with test data and context

func (*CmdTest) ParseOutputForCreate

func (test *CmdTest) ParseOutputForCreate(testData interface{}) error

Parse output result for creating service/policy/rolepolicy

func (*CmdTest) ParseOutputForGet

func (test *CmdTest) ParseOutputForGet(data interface{}) error

Parse output result for getting service/policy/rolepolicy

func (*CmdTest) PreExecute

func (test *CmdTest) PreExecute(testcase *TestCase, ctx *TestContext) error

Prepare for Test Execution. Set the default func in testcase

type CmdTestData

type CmdTestData struct {
	Param        string      //parameter string after spxctl command
	FileContent  interface{} //The content of File (JSON or PDL )
	OutputMsg    string      //Actual output Message
	OutputBody   interface{} //Actual output body for json object
	ExpectedMsg  string      //expected message for the command
	ExpectedBody interface{} //expected body about json object string
}

test data for spctl command

type GRpcClient

type GRpcClient struct {
	// contains filtered or unexported fields
}

func NewGRpcClient

func NewGRpcClient() *GRpcClient

func (*GRpcClient) CloseConnection

func (gc *GRpcClient) CloseConnection()

func (*GRpcClient) SetupConnection

func (gc *GRpcClient) SetupConnection() error

type GRpcTest

type GRpcTest struct {
	Client *GRpcClient
}

func (*GRpcTest) Execute

func (test *GRpcTest) Execute(testcase *TestCase, tc *TestContext) error

Execute current test with test data and context

func (*GRpcTest) PreExecute

func (test *GRpcTest) PreExecute(testcase *TestCase, tc *TestContext) error

Prepare for Test Execution. Set the default func in testcase

type GRpcTestData

type GRpcTestData struct {
	InputBody    interface{} //Optional. Request body for method
	OutputMsg    string      //Optional. Actual output Message
	OutputBody   interface{} //Optional. Actual output body for json object
	ExpectedMsg  string      //Optional. expected message for the command
	ExpectedBody interface{} //Optional. expected body about json object string
}

-------------------GRpcTest definition------------------------ test data for spxctl command

type RestClient

type RestClient struct {
	// contains filtered or unexported fields
}

func NewRestClient

func NewRestClient(endpoint string, curToken string, basicAuthName string, basicAuthPwd string) (*RestClient, error)

Get Rest Client if both curToken and basicAuth are specified, curToken would do effect

func NewRestClient_ADS

func NewRestClient_ADS() *RestClient

Get RestClient for Authz check

func NewRestClient_PMS

func NewRestClient_PMS() *RestClient

Get RestClient for policy management

func (*RestClient) Delete

func (client *RestClient) Delete(data interface{}) error

Do REST DELETE api method with specified data (RestTestData)

func (*RestClient) Get

func (client *RestClient) Get(data interface{}) error

Do REST GET api method with specified data (RestTestData)

func (*RestClient) Post

func (client *RestClient) Post(data interface{}) error

Do REST POST api method with specified data (RestTestData)

func (*RestClient) Prefix

func (client *RestClient) Prefix() string

Get prefix of RestClient

func (*RestClient) Put

func (client *RestClient) Put(data interface{}) error

Do REST PUT api method with specified data (RestTestData)

func (*RestClient) SetBasicAuth

func (client *RestClient) SetBasicAuth(name string, pwd string)

Set baisc auth userName/userPwd of RestClient

func (*RestClient) SetPrefix

func (client *RestClient) SetPrefix(newPrefix string)

Set prefix of RestClient

func (*RestClient) SetToken

func (client *RestClient) SetToken(newToken string)

Set token of RestClient

func (*RestClient) Token

func (client *RestClient) Token() string

Get token of RestClient

type RestTest

type RestTest struct {
	Client *RestClient
}

Rest Test including RestClient and implementing Executer interface

func (*RestTest) Execute

func (test *RestTest) Execute(testcase *TestCase, ctx *TestContext) error

Execute current test with test data and context

func (*RestTest) PreExecute

func (test *RestTest) PreExecute(testcase *TestCase, ctx *TestContext) error

Prepare for Test Execution. Set the default func in testcase

type RestTestData

type RestTestData struct {
	URI string

	ExpectedStatus int
	InputBody      interface{} //input data for test
	OutputBody     interface{} //Actual output data
	ExpectedBody   interface{} //Expected output data
	// contains filtered or unexported fields
}

TestData for REST API testing

type TestCase

type TestCase struct {
	Name           string                                            //Required. test name
	Enabled        bool                                              //Required. test case would be execute or not
	Executer       func() TestExecuter                               //Required. function to get the client, if not specified, default client would be created accroding to the type of Data
	Method         string                                            //Method for current Testing
	Data           interface{}                                       //Required. The input/output and func used during the test
	PreTestFunc    func(data interface{}, context *TestContext)      //Optional. function executed before test. Optional
	PostTestFunc   func(data interface{}, context *TestContext)      //Optional. function executed after test/ If not specified, default func would be used
	VerifyTestFunc func(data interface{}, context *TestContext) bool //Optional. function executed to verify test result. If not specified, default func would be used
}

TestCase struct

func GetRestTestData_CreatePolicy

func GetRestTestData_CreatePolicy(step string, srvName string, policyName string, effect string, principals [][]string, resource string, actions []string) TestCase

GetRestTestData for creating policy

func GetRestTestData_CreateRolePolicy

func GetRestTestData_CreateRolePolicy(step string, srvName string, rolePolicyName string, effect string, roles []string, principals []string, resources []string) TestCase

GetRestTestData for creating rolepolicy

func GetRestTestData_CreateService

func GetRestTestData_CreateService(step string, srvName string) TestCase

GetRestTestData for creating service

func GetRestTestData_DeleteService

func GetRestTestData_DeleteService(step string, srvName string) TestCase

GetRestTestData for deleting service

func GetTestData_Sleep

func GetTestData_Sleep(sleep int) TestCase

Get TestData for sleeping a while (in ms)

func (*TestCase) SetPostTestFunc

func (tc *TestCase) SetPostTestFunc(curFunc func(data interface{}, context *TestContext))

Set PostTestFunc if PostTestFunc is nil

func (*TestCase) SetPreTestFunc

func (tc *TestCase) SetPreTestFunc(curFunc func(data interface{}, context *TestContext))

Set PreTestFunc if PreTestFunc is nil

func (*TestCase) SetVerifyTestFunc

func (tc *TestCase) SetVerifyTestFunc(curFunc func(data interface{}, context *TestContext) bool)

Set VerifyTestFunc if VerifyTestFunc is nil

type TestContext

type TestContext struct {
	NameIDMap     map[string]string      //Name:ID map. Name is specified by user, ID is generated by speedle
	NameObjectMap map[string]interface{} //Name:Object map.
	FileName      string                 //File Name used in test
}

Test context

type TestExecuter

type TestExecuter interface {
	PreExecute(testcase *TestCase, context *TestContext) (err error)
	Execute(testcase *TestCase, context *TestContext) (err error)
}

Test Executer interface

func NewCmdTest

func NewCmdTest() TestExecuter

func NewGRpcTestExecuter

func NewGRpcTestExecuter() TestExecuter

func NewRestTestExecuter

func NewRestTestExecuter() TestExecuter

New RestTest

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL