Skip to content

Commit

Permalink
add spec tests for gosec fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ghbren committed Jun 11, 2020
1 parent a4b5052 commit 7e7346e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module test/hello

require (
test123.test456.test789/test2 v0.123456
)

go 1.13
5 changes: 5 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hello

func Hello() string {
return "Hello!"
}
10 changes: 10 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/hello_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hello

import "testing"

func TestHello(t *testing.T) {
want := "Hello!"
if got := Hello(); got != want {
t.Errorf("Hello() = %q, want %q", got, want)
}
}
11 changes: 11 additions & 0 deletions spec/lib/salus/scanners/gosec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

before { scanner.run }

context 'go get ./... fails' do
let(:repo) { Salus::Repo.new('spec/fixtures/gosec/bad_gomod_app') }

it 'should display go get error and not run gosec' do
expect(scanner.should_run?).to eq(true)
expect(scanner.report.passed?).to eq(false)
err_msg = scanner.report.to_h.fetch(:errors).first[:message]
expect(err_msg).to include('Unable to start gosec because go get ./... failed.')
end
end

context 'non-go project' do
let(:repo) { Salus::Repo.new('spec/fixtures/blank_repository') }

Expand Down

0 comments on commit 7e7346e

Please sign in to comment.