Skip to content

Commit

Permalink
🌱 Add test for attestor CLI (#3232)
Browse files Browse the repository at this point in the history
- Add a test for the `addSignFlags` function

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan authored Jun 30, 2023
1 parent 15b9046 commit 13a0e7f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions attestor/command/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2023 OpenSSF Scorecard 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 command

import (
"testing"

"github.com/spf13/cobra"
)

func Test_addSignFlags(t *testing.T) {
type args struct {
cmd *cobra.Command
}
testName := "Test addSignFlags"
testArgs := args{
cmd: &cobra.Command{},
}

t.Run(testName, func(t *testing.T) {
addSignFlags(testArgs.cmd)
// persistent flags of Image being set has to be tested in the integration test
if testArgs.cmd.PersistentFlags().Lookup("image") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'image'")
}
if testArgs.cmd.PersistentFlags().Lookup("attestation-project") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'attestation-project'")
}
if testArgs.cmd.PersistentFlags().Lookup("overwrite") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'overwrite'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-key-name") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-key-name'")
}
if testArgs.cmd.PersistentFlags().Lookup("kms-digest-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'kms-digest-alg'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pgp-passphrase") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pgp-passphrase'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-private-key") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-private-key'")
}
if testArgs.cmd.PersistentFlags().Lookup("pkix-alg") == nil {
t.Errorf("addSignFlags() did not add persistent flag 'pkix-alg'")
}
})
}

0 comments on commit 13a0e7f

Please sign in to comment.