any error needs to be recorded
|
f . AddError ( err . Error ( ) )
}
}
return response . Profiles
}
func checkNumberOfProfiles ( f * frisby . Frisby , profiles [ ] ConfigurationProfile , expected int ) {
if len ( profiles ) != expected {
f . AddError ( fmt . Sprintf ( "Number of returned configuration profiles %d differs from expected number %d" , len ( profiles ) , expected ) )
}
}
func checkInitialListOfConfigurationProfiles ( ) {
f := frisby . Create ( "Check list of configuration profiles" )
f . Get ( API_URL + "/client/profile" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
profiles := readConfigurationProfilesFromResponse ( f )
checkNumberOfProfiles ( f , profiles , 4 )
expected := [ ] ConfigurationProfile {
{ 0 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg1" } ,
{ 1 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg2" } ,
{ 2 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-10-11T00:00:00Z" , "tester" , "cfg3" } ,
{ 3 , `{"no_op":"Y", "watch":["d","e"]}` , "2019-10-11T00:00:00Z" , "tester" , "cfg3" } ,
}
compareConfigurationProfiles ( f , profiles , expected )
f . PrintReport ( )
}
func checkGetExistingConfigurationProfile ( ) {
f := frisby . Create ( "Check getting configuration profile that exists" )
f . Get ( API_URL + "/client/profile/0" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
profile := readConfigurationProfileFromResponse ( f )
expected := ConfigurationProfile { 0 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg1" }
if profile != expected {
f . AddError ( fmt . Sprintf ( "Different profile is returned for profile ID = 0: %v != %v" , profile , expected ) )
}
f . PrintReport ( )
}
func checkGetNonexistentConfigurationProfile ( ) {
f := frisby . Create ( "Check getting configuration profile that does not exist" )
f . Get ( API_URL + "/client/profile/1234" )
f . Send ( )
f . ExpectStatus ( 404 )
f . PrintReport ( )
}
func checkChangeConfigurationProfile ( ) {
f := frisby . Create ( "Check changing configuration profile" )
f . Put ( API_URL + "client/profile/3?username=foo&description=bar" )
f . Req . Body = strings . NewReader ( `{"no_op":"Z", "watch":[]}` )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
}
func checkListOfConfigurationProfilesWithUpdatedItem ( ) {
f := frisby . Create ( "Check list of configuration profiles with new item" )
f . Get ( API_URL + "/client/profile" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
profiles := readConfigurationProfilesFromResponse ( f )
checkNumberOfProfiles ( f , profiles , 4 )
expected := [ ] ConfigurationProfile {
{ 0 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg1" } ,
{ 1 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg2" } ,
{ 2 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-10-11T00:00:00Z" , "tester" , "cfg3" } ,
{ 3 , `{"no_op":"Z", "watch":[]}` , "2019-10-11T00:00:00Z" , "foo" , "bar" } ,
}
compareConfigurationProfiles ( f , profiles , expected )
f . PrintReport ( )
}
func checkChangeNonExistingConfigurationProfile ( ) {
f := frisby . Create ( "Check changing non existing configuration profile" )
f . Put ( API_URL + "client/profile/35?username=foo&description=bar" )
f . Req . Body = strings . NewReader ( `{"no_op":"Z", "watch":[]}` )
f . Send ( )
f . ExpectStatus ( 404 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
}
func checkDeleteConfigurationProfile ( ) {
f := frisby . Create ( "Check deletion of configuration profile" )
f . Delete ( API_URL + "client/profile/3?" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
}
func checkDeleteNonexistingConfigurationProfile ( ) {
f := frisby . Create ( "Check deletion of non existing configuration profile" )
f . Delete ( API_URL + "client/profile/35?" )
f . Send ( )
f . ExpectStatus ( 404 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
}
func checkCreateNewConfigurationProfile ( ) {
f := frisby . Create ( "Check creating new configuration profile" )
f . Post ( API_URL + "client/profile?username=tester2&description=description" )
f . Req . Body = strings . NewReader ( `{"no_op":"W", "watch":[]}` )
f . Send ( )
f . ExpectStatus ( 201 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
}
func checkListOfConfigurationProfilesWithDeletedItem ( ) {
f := frisby . Create ( "Check list of configuration profiles with deleted item" )
f . Get ( API_URL + "/client/profile" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
profiles := readConfigurationProfilesFromResponse ( f )
checkNumberOfProfiles ( f , profiles , 3 )
expected := [ ] ConfigurationProfile {
{ 0 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg1" } ,
{ 1 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg2" } ,
{ 2 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-10-11T00:00:00Z" , "tester" , "cfg3" } ,
}
compareConfigurationProfiles ( f , profiles , expected )
f . PrintReport ( )
}
func checkListOfConfigurationProfilesWithAddedItem ( ) {
f := frisby . Create ( "Check list of configuration profiles with added item" )
f . Get ( API_URL + "/client/profile" )
f . Send ( )
f . ExpectStatus ( 200 )
f . ExpectHeader ( "Content-Type" , "application/json; charset=utf-8" )
profiles := readConfigurationProfilesFromResponse ( f )
checkNumberOfProfiles ( f , profiles , 4 )
expected := [ ] ConfigurationProfile {
{ 0 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg1" } ,
{ 1 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-01-01T00:00:00Z" , "tester" , "cfg2" } ,
{ 2 , `{"no_op":"X", "watch":["a","b","c"]}` , "2019-10-11T00:00:00Z" , "tester" , "cfg3" } ,
{ 3 , `{"no_op":"W", "watch":[]}` , "2019-10-11T00:00:00Z" , "tester2" , "description" } ,
}
compareConfigurationProfilesWithoutID ( f , profiles , expected )
f . PrintReport ( )
}
|