-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RotateContext handle command tests (#252)
Added tests for RotateContextHandle command * Added a test to check and report invalid handle with a test handle (moved to negativeCases.go, taken care in PR 255, as a common negative case test) The following are part of this PR: * RotateHandle in default context * RotateHandle in non-default context * RotateHandle in with TARGET_DEFAULT flag
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
package verification | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestRotateContextHandle(d TestDPEInstance, c DPEClient, t *testing.T) { | ||
simulation := false | ||
handle := getInitialContextHandle(d, c, t, simulation) | ||
|
||
// Check whether the rotated context handle is a random context handle | ||
handle, err := c.RotateContextHandle(handle, RotateContextHandleFlags(0)) | ||
if err != nil { | ||
t.Fatalf("[FATAL]: Could not rotate context handle: %v", err) | ||
} | ||
if *handle == DefaultContextHandle { | ||
t.Errorf("[ERROR]: Expected random context handle but have got default context %v", handle) | ||
} | ||
|
||
// Rotate back the handle to default handle for subsequent tests | ||
// This works only when there is no default handle available | ||
handle, err = c.RotateContextHandle(handle, TargetIsDefault) | ||
if err != nil { | ||
t.Fatalf("[FATAL]: Could not rotate context handle: %v", err) | ||
} | ||
if *handle != DefaultContextHandle { | ||
t.Errorf("[ERROR]: TARGET_IS_DEFAULT is set, have got %v but want %v", handle, DefaultContextHandle) | ||
} | ||
|
||
// Check for error when a default context handle exists already and handle is rotated to default handle | ||
// Since, there cannot be more than one default context handle | ||
_, err = c.RotateContextHandle(handle, TargetIsDefault) | ||
if err == nil { | ||
t.Fatalf("[FATAL]: Should return %q for default context, but returned no error", StatusInvalidArgument) | ||
} else if !errors.Is(err, StatusInvalidArgument) { | ||
t.Fatalf("[FATAL]: Incorrect error type. Should return %q, but returned %q", StatusInvalidArgument, err) | ||
} | ||
} | ||
|
||
func TestRotateContextHandleSimulation(d TestDPEInstance, c DPEClient, t *testing.T) { | ||
simulation := true | ||
handle := getInitialContextHandle(d, c, t, simulation) | ||
defer func() { | ||
c.DestroyContext(handle, DestroyDescendants) | ||
}() | ||
|
||
// Check whether the rotated context handle is a random context handle | ||
handle, err := c.RotateContextHandle(handle, RotateContextHandleFlags(0)) | ||
if err != nil { | ||
t.Fatalf("[FATAL]: Could not rotate context handle: %v", err) | ||
} | ||
if *handle == DefaultContextHandle { | ||
t.Errorf("[ERROR]: Expected random context handle but have got default context %v", handle) | ||
} | ||
|
||
// In simulated context, the handle cannot be rotated to default handle | ||
// Since, it is not allowed to have a both of default and non-default context handles together | ||
_, err = c.RotateContextHandle(handle, TargetIsDefault) | ||
if err == nil { | ||
t.Fatalf("[FATAL]: Should return %q for simulation context, but returned no error", StatusInvalidArgument) | ||
} else if !errors.Is(err, StatusInvalidArgument) { | ||
t.Fatalf("[FATAL]: Incorrect error type. Should return %q, but returned %q", StatusInvalidArgument, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters