Skip to content

Commit

Permalink
add test for allEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Oct 16, 2023
1 parent f432802 commit 75895ec
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/api/attestationconfigapi/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ go_library(

go_test(
name = "cli_test",
srcs = ["delete_test.go"],
srcs = [
"delete_test.go",
"main_test.go",
],
embed = [":cli_lib"],
deps = [
"//internal/verify",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],
Expand Down
2 changes: 1 addition & 1 deletion internal/api/attestationconfigapi/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func runCmd(cmd *cobra.Command, _ []string) (retErr error) {
return nil
}

func allEqual[T comparable](args ...T) bool {
func allEqual(args ...verify.TCBVersion) bool {
if len(args) < 2 {
return true
}
Expand Down
27 changes: 27 additions & 0 deletions internal/api/attestationconfigapi/cli/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"testing"

"github.com/edgelesssys/constellation/v2/internal/verify"
"github.com/stretchr/testify/assert"
)

func TestAllEqual(t *testing.T) {
// Test case 1: One input arg
assert.True(t, allEqual(verify.TCBVersion{Bootloader: 1, Microcode: 2, SNP: 3, TEE: 4}), "Expected allEqual to return true for one input arg, but got false")

// Test case 2: Three input args that are equal
assert.True(t, allEqual(
verify.TCBVersion{Bootloader: 1, Microcode: 2, SNP: 3, TEE: 4},
verify.TCBVersion{Bootloader: 1, Microcode: 2, SNP: 3, TEE: 4},
verify.TCBVersion{Bootloader: 1, Microcode: 2, SNP: 3, TEE: 4},
), "Expected allEqual to return true for three equal input args, but got false")

// Test case 3: Three input args where second and third element are different
assert.False(t, allEqual(
verify.TCBVersion{Bootloader: 1, Microcode: 2, SNP: 3, TEE: 4},
verify.TCBVersion{Bootloader: 2, Microcode: 2, SNP: 3, TEE: 4},
verify.TCBVersion{Bootloader: 2, Microcode: 3, SNP: 3, TEE: 4},
), "Expected allEqual to return false for three input args with different second and third elements, but got true")
}

0 comments on commit 75895ec

Please sign in to comment.