diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 72f8098..13da40f 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -13,9 +13,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3.2.0 + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: - version: v1.50.0 + version: v1.55.2 only-new-issues: false args: --config .golangci.yml --timeout=5m diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 330c47b..80849b6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -26,7 +26,7 @@ jobs: - name: Setup Go uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a #v3.2.1 with: - go-version: '1.20' + go-version-file: 'go.mod' - uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 #v3.1.2 diff --git a/.golangci.yml b/.golangci.yml index 4061e2e..19bfe20 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,8 @@ linters-settings: govet: check-shadowing: true + cyclop: + max-complexity: 15 maligned: suggest-new: true goconst: @@ -10,7 +12,7 @@ linters-settings: sections: - standard # Captures all standard packages if they do not match another section. - default # Contains all imports that could not be matched to another section type. - - prefix(github.com/falcosecurity/peribolos-owners-syncer) # Groups all imports with the specified Prefix. + - prefix(github.com/falcosecurity/peribolos-syncer) # Groups all imports with the specified Prefix. tagliatelle: case: rules: @@ -31,14 +33,19 @@ linters: - ireturn - lll - nonamedreturns - - wrapcheck - varnamelen + - depguard + - wrapcheck issues: exclude-rules: - path: / linters: - typecheck + - path: _test.go + linters: + - revive + - ineffassign + - staticcheck + - errcheck -run: - skip-dirs: [] diff --git a/Makefile b/Makefile index 7f3442c..1181d9f 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ lint: golangci-lint .PHONY: golangci-lint golangci-lint: - @$(go) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0 + @$(go) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 .PHONY: gofumpt gofumpt: diff --git a/cmd/sync/github/constants.go b/cmd/sync/github/constants.go index 3e43062..f1f03b2 100644 --- a/cmd/sync/github/constants.go +++ b/cmd/sync/github/constants.go @@ -29,4 +29,6 @@ peribolos-syncer sync github --org=acme --team=app-maintainers syncerSignature = "Autogenerated with [peribolos-syncer](https://github.com/falcosecurity/peribolos-syncer)." ownersDoc = "https://docs.prow.k8s.io/docs/components/plugins/approve/approvers/#overview" peribolosConfigFile = "org.yaml" + + modeConfigFile = 0o644 ) diff --git a/cmd/sync/github/sync_github.go b/cmd/sync/github/sync_github.go index 53f0986..e8c8846 100644 --- a/cmd/sync/github/sync_github.go +++ b/cmd/sync/github/sync_github.go @@ -47,7 +47,7 @@ type options struct { publicGPGKeyPath string github syncergithub.GitHubOptions - orgs *orgs.PeribolosOptions + orgs *orgs.Options owners *owners.OwnersLoadingOptions git.ListOptions @@ -60,7 +60,7 @@ func New() *cobra.Command { author: gitobject.Signature{}, github: syncergithub.GitHubOptions{}, owners: &owners.OwnersLoadingOptions{}, - orgs: &orgs.PeribolosOptions{}, + orgs: &orgs.Options{}, } cmd := &cobra.Command{ @@ -94,19 +94,19 @@ func New() *cobra.Command { func (o *options) validate() error { if o.GitHubOrg == "" { - return fmt.Errorf("github organization name is empty") + return errors.New("github organization name is empty") } if o.GitHubTeam == "" { - return fmt.Errorf("github team name is empty") + return errors.New("github team name is empty") } if o.author.Name == "" { - return fmt.Errorf("git author name is empty") + return errors.New("git author name is empty") } if o.author.Email == "" { - return fmt.Errorf("git author email is empty") + return errors.New("git author email is empty") } if o.publicGPGKeyPath == "" { @@ -132,6 +132,7 @@ func (o *options) validate() error { return nil } +//nolint:funlen func (o *options) Run(_ *cobra.Command, _ []string) error { if err := o.validate(); err != nil { return err @@ -178,7 +179,7 @@ func (o *options) Run(_ *cobra.Command, _ []string) error { } // Synchronize the Github Team config with Approvers. - if err := orgs.AddTeamMembers(config, o.GitHubOrg, o.GitHubTeam, people); err != nil { + if err = orgs.AddTeamMembers(config, o.GitHubOrg, o.GitHubTeam, people); err != nil { return errors.Wrap(err, "error updating maintainers github team from leaf approvers") } @@ -272,6 +273,7 @@ func (o *options) loadPeopleFromOwners(owners repoowners.RepoOwner) []string { switch { // Limiting the scope of the roles. case o.owners.ConfigPath != "": + //nolint:gocritic if o.owners.ApproversOnly { // Approvers of the subpart of the repository. people = maps.Keys(owners.Approvers(o.owners.ConfigPath).Set()) @@ -303,7 +305,7 @@ func (o *options) flushConfig(config *peribolos.FullConfig, configPath string) e return errors.Wrap(err, "error recompiling the peribolos config") } - if err = os.WriteFile(path.Join(configPath, o.orgs.ConfigPath), b, 0644); err != nil { + if err = os.WriteFile(path.Join(configPath, o.orgs.ConfigPath), b, modeConfigFile); err != nil { return errors.Wrap(err, "error writing the recompiled peribolos config") } diff --git a/cmd/version/version.go b/cmd/version/version.go index 0f98598..d9c6bf9 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -23,21 +23,21 @@ import ( "github.com/falcosecurity/peribolos-syncer/internal/output" ) -var ( - // Semantic version that refers to ghe version (git tag) of syncer that is released. +const ( + // Semantic Version that refers to ghe Version (git tag) of syncer that is released. // NOTE: The $Format strings are replaced during 'git archive' thanks to the // companion .gitattributes file containing 'export-subst' in this same // directory. See also https://git-scm.com/docs/gitattributes. - semVersion = "v0.0.0-master+$Format:%H$" + SemVersion = "v0.0.0-master+$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD). - gitCommit = "$Format:%H$" + GitCommit = "$Format:%H$" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ'). - buildDate = "1970-01-01T00:00:00Z" + BuildDate = "1970-01-01T00:00:00Z" ) -type version struct { +type Version struct { SemVersion string `json:"sem_version"` GitCommit string `json:"git_commit"` BuildDate string `json:"build_date"` @@ -46,13 +46,13 @@ type version struct { Platform string `json:"platform"` } -// New returns a new version command. +// New returns a new Version command. func New() *cobra.Command { - v := newVersion() + v := NewVersion() cmd := &cobra.Command{ - Use: "version", - Short: "Return the syncer version", + Use: "Version", + Short: "Return the syncer Version", RunE: func(cmd *cobra.Command, args []string) error { return v.Print() }, @@ -61,18 +61,19 @@ func New() *cobra.Command { return cmd } -func (o *version) Print() error { +func (o *Version) Print() error { output.Print(o.SemVersion) + return nil } -func newVersion() version { +func NewVersion() Version { // These variables usually come from -ldflags settings and in their // absence fallback to the ones defined in the var section. - return version{ - SemVersion: semVersion, - GitCommit: gitCommit, - BuildDate: buildDate, + return Version{ + SemVersion: SemVersion, + GitCommit: GitCommit, + BuildDate: BuildDate, GoVersion: runtime.Version(), Compiler: runtime.Compiler, Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), diff --git a/cmd/version/version_test.go b/cmd/version/version_test.go index 5d5fa3c..8bc7aeb 100644 --- a/cmd/version/version_test.go +++ b/cmd/version/version_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package version +package version_test import ( "fmt" @@ -21,10 +21,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + + cmd "github.com/falcosecurity/peribolos-syncer/cmd/version" ) var _ = Describe("Version", func() { - version := &version{ + version := &cmd.Version{ SemVersion: "0.0.0", GitCommit: "ef30d58", BuildDate: "2024-03-25_17:55:07", @@ -33,19 +35,19 @@ var _ = Describe("Version", func() { Platform: "linux/test", } - Context("testing version Print function", func() { + Context("testing Version Print function", func() { It("should not error", func() { Expect(version.Print()).Error().ShouldNot(HaveOccurred()) }) }) - Context("testing newVersion function", func() { - It("should return the expected version struct", func() { - v := newVersion() + Context("testing NewVersion function", func() { + It("should return the expected Version struct", func() { + v := cmd.NewVersion() Expect(v.Compiler).Should(Equal(runtime.Compiler)) - Expect(v.SemVersion).Should(Equal(semVersion)) - Expect(v.GitCommit).Should(Equal(gitCommit)) - Expect(v.BuildDate).Should(Equal(buildDate)) + Expect(v.SemVersion).Should(Equal(cmd.SemVersion)) + Expect(v.GitCommit).Should(Equal(cmd.GitCommit)) + Expect(v.BuildDate).Should(Equal(cmd.BuildDate)) Expect(v.GoVersion).Should(Equal(runtime.Version())) Expect(v.Platform).Should(Equal(fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))) }) diff --git a/internal/git/git.go b/internal/git/git.go index 46e57c5..c1290af 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -15,20 +15,21 @@ package git import ( - gitobject "github.com/go-git/go-git/v5/plumbing/object" "time" "github.com/ProtonMail/go-crypto/openpgp" - "github.com/go-git/go-git/v5" gitplumbing "github.com/go-git/go-git/v5/plumbing" + gitobject "github.com/go-git/go-git/v5/plumbing/object" "github.com/google/uuid" "github.com/pkg/errors" ) func NewEphemeralGitBranch(repo *git.Repository, worktree *git.Worktree) (string, error) { id := uuid.New() + refName := id.String() + headRef, err := repo.Head() if err != nil { return "", errors.Wrap(err, "error getting repository HEAD reference") @@ -52,7 +53,8 @@ func NewEphemeralGitBranch(repo *git.Repository, worktree *git.Worktree) (string } func StageAndCommit(repo *git.Repository, worktree *git.Worktree, author *gitobject.Signature, - pgpEntity *openpgp.Entity, stagePath, commitMessage string) error { + pgpEntity *openpgp.Entity, stagePath, commitMessage string, +) error { if worktree == nil { return errors.New("worktree cannot be empty") } diff --git a/internal/github/github.go b/internal/github/github.go index 3796572..2e26f01 100644 --- a/internal/github/github.go +++ b/internal/github/github.go @@ -22,7 +22,6 @@ import ( "github.com/go-git/go-git/v5" githttp "github.com/go-git/go-git/v5/plumbing/transport/http" - "github.com/pkg/errors" "github.com/spf13/pflag" "k8s.io/test-infra/pkg/flagutil" @@ -76,10 +75,9 @@ func (o *GitHubOptions) GetGitClientFactory() (gitv2.ClientFactory, error) { return factory, nil } -func (o *GitHubOptions) ForkRepository(githubClient prowgithub.Client, - githubOrg, githubRepo, token string) (*git.Repository, *git.Worktree, string, error) { - +func (o *GitHubOptions) ForkRepository(githubClient prowgithub.Client, githubOrg, githubRepo, token string) (*git.Repository, *git.Worktree, string, error) { githubClient.Used() + path, err := os.MkdirTemp("", "orgs") if err != nil { return nil, nil, "", errors.Wrap(err, "error creating temporary directory for cloning git repository") diff --git a/internal/owners/owners.go b/internal/owners/owners.go index 931a1df..47536db 100644 --- a/internal/owners/owners.go +++ b/internal/owners/owners.go @@ -36,7 +36,6 @@ type Handle string // //nolint:revive type OwnersLoadingOptions struct { - // RepositoryName represents the git repository name at which load the Owners config. RepositoryName string @@ -74,7 +73,8 @@ func (o *OwnersLoadingOptions) AddPFlags(pfs *pflag.FlagSet) { // It wraps around repoowners.NewClient facilitating the client build configuration with default settings. // It possibly returns an error. func NewClient(githubClient github.Client, - gitClientFactory gitv2.ClientFactory) *repoowners.Client { + gitClientFactory gitv2.ClientFactory, +) *repoowners.Client { mdYAMLEnabled := func(org, repo string) bool { return false } diff --git a/internal/owners/owners_test.go b/internal/owners/owners_test.go index d7e114c..c2cca49 100644 --- a/internal/owners/owners_test.go +++ b/internal/owners/owners_test.go @@ -27,12 +27,6 @@ import ( . "github.com/falcosecurity/peribolos-syncer/internal/owners" ) -const ( - repo = "peribolos-syncer" - ref = "main" - ownersPath = "OWNERS" -) - var _ = Describe("Creating new client", func() { var ( ownersClient *repoowners.Client diff --git a/pkg/peribolos/config.go b/pkg/peribolos/config.go index 750eaf9..d1da270 100644 --- a/pkg/peribolos/config.go +++ b/pkg/peribolos/config.go @@ -86,7 +86,6 @@ func AddTeamMaintainers(config *peribolos.FullConfig, org, team string, maintain func AddTeamMembers(config *peribolos.FullConfig, org, team string, members []string) error { orgConfig, ok := config.Orgs[org] if !ok { - //nolint:goerr113 return errors.New("organization not found in peribolos config") } diff --git a/pkg/peribolos/peribolos.go b/pkg/peribolos/peribolos.go index 8adbf0e..2970bce 100644 --- a/pkg/peribolos/peribolos.go +++ b/pkg/peribolos/peribolos.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/pflag" ) -type PeribolosOptions struct { +type Options struct { ConfigRepo string ConfigPath string ConfigBaseRef string @@ -30,12 +30,12 @@ const ( gitRef = "master" ) -func NewOptions() *PeribolosOptions { - return &PeribolosOptions{} +func NewOptions() *Options { + return &Options{} } // Validate validates peribolos options. It possibly returns an error. -func (o *PeribolosOptions) Validate() error { +func (o *Options) Validate() error { if o.ConfigRepo == "" { //nolint:goerr113 return fmt.Errorf("organization config file's github repository name is empty") @@ -45,7 +45,7 @@ func (o *PeribolosOptions) Validate() error { } // AddPFlags adds peribolos options' flags to a flag set. -func (o *PeribolosOptions) AddPFlags(pfs *pflag.FlagSet) { +func (o *Options) AddPFlags(pfs *pflag.FlagSet) { pfs.StringVar(&o.ConfigRepo, "peribolos-config-repository", "", "The name of the github repository that contains the peribolos organization config file") pfs.StringVarP(&o.ConfigPath, "peribolos-config-path", "c", "org.yaml", "The path to the peribolos organization config file from the root of the Git repository") pfs.StringVar(&o.ConfigBaseRef, "peribolos-config-git-ref", gitRef, "The base Git reference at which pull the peribolos config repository") diff --git a/pkg/peribolos/peribolos_test.go b/pkg/peribolos/peribolos_test.go index de72091..144a736 100644 --- a/pkg/peribolos/peribolos_test.go +++ b/pkg/peribolos/peribolos_test.go @@ -35,9 +35,7 @@ const ( ) var _ = Describe("Creating new Peribolos config", func() { - var ( - config *peribolos.FullConfig - ) + var config *peribolos.FullConfig BeforeEach(func() { config = NewConfig() @@ -58,7 +56,6 @@ var _ = Describe("Loading Peribolos config from filesystem", func() { ) Context("config is a valid peribolos fullconfig", func() { - BeforeEach(func() { configYaml = fmt.Sprintf(` orgs: @@ -78,37 +75,34 @@ orgs: `, org, admin, admin, member, team, admin, admin, member) err = yaml.Unmarshal([]byte(configYaml), config) - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) - file, err := fs.Create(filename) - Expect(err).To(BeNil()) + file, _ := fs.Create(filename) Expect(file).ToNot(BeNil()) - _, err = file.Write([]byte(configYaml)) - Expect(err).To(BeNil()) + file.Write([]byte(configYaml)) config, err = LoadConfigFromFilesystem(fs, filename) }) It("should not error", func() { Expect(config).ToNot(BeNil()) - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) }) It("should build correct teams", func() { - Expect(len(config.Orgs[org].Teams)).To(Equal(1)) + Expect(config.Orgs[org].Teams).To(HaveLen(1)) }) It("should build correct teams maintainers", func() { - Expect(len(config.Orgs[org].Teams[team].Maintainers)).To(Equal(1)) + Expect(config.Orgs[org].Teams[team].Maintainers).To(HaveLen(1)) }) It("should build correct teams members", func() { - Expect(len(config.Orgs[org].Teams[team].Members)).To(Equal(2)) + Expect(config.Orgs[org].Teams[team].Members).To(HaveLen(2)) }) }) Context("config file is not valid", func() { - BeforeEach(func() { configYaml = `wrong` @@ -120,12 +114,9 @@ orgs: }) It("should error", func() { - Expect(err).ToNot(BeNil()) - }) - It("should return nil", func() { + Expect(err).To(HaveOccurred()) Expect(config).To(BeNil()) }) - }) }) @@ -151,21 +142,19 @@ var _ = Describe("Updating Team's members", func() { }) Context("the org exists", func() { - Context("the team exists", func() { BeforeEach(func() { err = AddTeamMembers(config, org, team, []string{"charlie"}) }) It("should not error", func() { - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) }) It("should add the member to the specified team", func() { - Expect(len(config.Orgs[org].Teams[team].Members)).To(Equal(3)) + Expect(config.Orgs[org].Teams[team].Members).To(HaveLen(3)) }) It("should not remove existing members", func() { Expect(config.Orgs[org].Teams[team].Members).To(Equal([]string{admin, member, "charlie"})) }) - }) Context("the team does not exist", func() { @@ -174,30 +163,28 @@ var _ = Describe("Updating Team's members", func() { }) It("should error", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("should not change the config", func() { - Expect(len(config.Orgs[org].Teams)).To(Equal(1)) + Expect(config.Orgs[org].Teams).To(HaveLen(1)) Expect(config.Orgs[org].Teams[team].Members).To(Equal([]string{"alice", "bob"})) Expect(config.Orgs[org].Teams[team].Maintainers).To(Equal([]string{"alice"})) }) - }) }) Context("the org does not exist", func() { - BeforeEach(func() { err = AddTeamMembers(config, "nonexistent", team, []string{"charlie"}) }) It("should error", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("should not change the config", func() { - Expect(len(config.Orgs[org].Teams)).To(Equal(1)) + Expect(config.Orgs[org].Teams).To(HaveLen(1)) Expect(config.Orgs[org].Teams[team].Members).To(Equal([]string{"alice", "bob"})) Expect(config.Orgs[org].Teams[team].Maintainers).To(Equal([]string{"alice"})) }) @@ -226,21 +213,19 @@ var _ = Describe("Updating Team's maintainers", func() { }) Context("the org exists", func() { - Context("the team exists", func() { BeforeEach(func() { err = AddTeamMaintainers(config, org, team, []string{"charlie"}) }) It("should not error", func() { - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) }) It("should add the member to the specified team", func() { - Expect(len(config.Orgs[org].Teams[team].Maintainers)).To(Equal(2)) + Expect(config.Orgs[org].Teams[team].Maintainers).To(HaveLen(2)) }) It("should not remove existing members", func() { Expect(config.Orgs[org].Teams[team].Maintainers).To(Equal([]string{admin, "charlie"})) }) - }) Context("the team does not exist", func() { @@ -249,30 +234,28 @@ var _ = Describe("Updating Team's maintainers", func() { }) It("should error", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("should not change the config", func() { - Expect(len(config.Orgs[org].Teams)).To(Equal(1)) + Expect(config.Orgs[org].Teams).To(HaveLen(1)) Expect(config.Orgs[org].Teams[team].Members).To(Equal([]string{"alice", "bob"})) Expect(config.Orgs[org].Teams[team].Maintainers).To(Equal([]string{"alice"})) }) - }) }) Context("the org does not exist", func() { - BeforeEach(func() { err = AddTeamMaintainers(config, "nonexistent", team, []string{"charlie"}) }) It("should error", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("should not change the config", func() { - Expect(len(config.Orgs[org].Teams)).To(Equal(1)) + Expect(config.Orgs[org].Teams).To(HaveLen(1)) Expect(config.Orgs[org].Teams[team].Members).To(Equal([]string{"alice", "bob"})) Expect(config.Orgs[org].Teams[team].Maintainers).To(Equal([]string{"alice"})) }) diff --git a/pkg/pgp/pgp.go b/pkg/pgp/pgp.go index d0fc2b7..3243f6c 100644 --- a/pkg/pgp/pgp.go +++ b/pkg/pgp/pgp.go @@ -25,9 +25,16 @@ import ( "github.com/pkg/errors" ) +const ( + CompressionLevel = 9 + SigKeyfiletimeSecs = uint32(86400 * 365) +) + // NewPGPEntity returns a new openGPG Entity and possibly with the identity name and email, // with the key pair of which the paths are specified. // It possibly returns an error. +// +//nolint:funlen func NewPGPEntity(authorName, authorEmail, publicKey, privateKey string) (*openpgp.Entity, error) { // Decode the public GPG key. pubKey, err := DecodePublicKeyFile(publicKey) @@ -52,7 +59,7 @@ func NewPGPEntity(authorName, authorEmail, publicKey, privateKey string) (*openp DefaultCipher: packet.CipherAES256, DefaultCompressionAlgo: packet.CompressionZLIB, CompressionConfig: &packet.CompressionConfig{ - Level: 9, + Level: CompressionLevel, }, RSABits: int(bits), } @@ -89,7 +96,7 @@ func NewPGPEntity(authorName, authorEmail, publicKey, privateKey string) (*openp }, } - keyLifetimeSecs := uint32(86400 * 365) + sigKeyfiletimeSecs := SigKeyfiletimeSecs // Add one additional key as signing and optionally encryption key. entity.Subkeys = make([]openpgp.Subkey, 1) @@ -106,7 +113,7 @@ func NewPGPEntity(authorName, authorEmail, publicKey, privateKey string) (*openp FlagEncryptStorage: true, FlagEncryptCommunications: true, IssuerKeyId: &entity.PrimaryKey.KeyId, - KeyLifetimeSecs: &keyLifetimeSecs, + KeyLifetimeSecs: &sigKeyfiletimeSecs, }, } diff --git a/pkg/pgp/pgp_test.go b/pkg/pgp/pgp_test.go index 1186482..b8b8be9 100644 --- a/pkg/pgp/pgp_test.go +++ b/pkg/pgp/pgp_test.go @@ -40,7 +40,7 @@ var _ = Describe("Decoding a PGP private key", func() { }) It("should fail", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("key be nil", func() { Expect(priv).To(BeNil()) @@ -50,11 +50,14 @@ var _ = Describe("Decoding a PGP private key", func() { When("the private key is a valid PGP armored private key", func() { BeforeEach(func() { e, _ := openpgp.NewEntity("", "", "", nil) + Expect(e).ToNot(BeNil()) filesystem := memfs.New() file, _ := filesystem.Create("mykey") + Expect(file).ToNot(BeNil()) armored, _ := armor.Encode(file, openpgp.PrivateKeyType, nil) + Expect(armored).ToNot(BeNil()) defer armored.Close() e.SerializePrivate(armored, nil) @@ -64,9 +67,9 @@ var _ = Describe("Decoding a PGP private key", func() { }) It("should not fail", func() { - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) }) - It("should not not be nil", func() { + It("should not be nil", func() { Expect(priv).ToNot(BeNil()) }) }) @@ -84,7 +87,7 @@ var _ = Describe("Decoding a PGP public key", func() { }) It("should fail", func() { - Expect(err).ToNot(BeNil()) + Expect(err).To(HaveOccurred()) }) It("key be nil", func() { Expect(pub).To(BeNil()) @@ -101,16 +104,17 @@ var _ = Describe("Decoding a PGP public key", func() { armored, _ := armor.Encode(file, openpgp.PublicKeyType, nil) defer armored.Close() - e.Serialize(armored) + err = e.Serialize(armored) + Expect(err).To(Succeed()) file.Seek(0, io.SeekStart) pub, err = pgp.DecodePublicKey(file) }) It("should not fail", func() { - Expect(err).To(BeNil()) + Expect(err).To(Succeed()) }) - It("should not not be nil", func() { + It("should not be nil", func() { Expect(pub).ToNot(BeNil()) }) })