-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vlidations for configs and panic instead of returning err
- Loading branch information
1 parent
9655dfe
commit ad2344a
Showing
6 changed files
with
183 additions
and
83 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 |
---|---|---|
@@ -1,11 +1,3 @@ | ||
fileignoreconfig: | ||
- filename: sftp/ssh/key_without_passphrase.pub | ||
checksum: 50e2a352407045a8ae28b9b53f2412d393f5697254dd1d3f26e41050f8186f23 | ||
- filename: sftp/ssh/key_with_passphrase.pub | ||
checksum: 39a2a36d4416dfb4df9f479d106d83fa45a12026140e945f1e279be5a983e4d7 | ||
- filename: sftp/ssh/key_without_passphrase | ||
checksum: 46831ea158a93518214983659d2d0991d9ca6da76f9e5428b749ce0fde031bde | ||
- filename: sftp/ssh/key_with_passphrase | ||
checksum: 6714cc1a10ad23ebc8b65290ac93e9996664ae4e1416094c57da90f32d75cf8d | ||
- filename: sftp/docker-compose.yml | ||
checksum: a320313a0715a649b1bf4c8db3e4cf45c2cdc9d5cbab154a4252b1d33ed8063c | ||
- filename: pkg/config/config.go | ||
checksum: 3d4547bb16555a9afb9277fa6d475c97f295d69b2eb9f000c9d89501f90f8c8c |
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
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
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
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
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,72 @@ | ||
package utils_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/arunvelsriram/sftp-exporter/pkg/utils" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestIsEmpty(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in string | ||
expected bool | ||
}{ | ||
{ | ||
name: "empty string", | ||
in: "", | ||
expected: true, | ||
}, | ||
{ | ||
name: "non-empty string", | ||
in: "some value", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
actual := utils.IsEmpty(test.in) | ||
|
||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestIsNotEmpty(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in string | ||
expected bool | ||
}{ | ||
{ | ||
name: "empty string", | ||
in: "", | ||
expected: false, | ||
}, | ||
{ | ||
name: "non-empty string", | ||
in: "some value", | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
actual := utils.IsNotEmpty(test.in) | ||
|
||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func TestPanicIfErrShouldPanicForErr(t *testing.T) { | ||
err := fmt.Errorf("some error") | ||
|
||
assert.PanicsWithValue(t, "some error", func() { utils.PanicIfErr(err) }) | ||
} | ||
|
||
func TestPanicIfErrShouldNotPanicWhenErrIsNil(t *testing.T) { | ||
assert.NotPanics(t, func() { utils.PanicIfErr(nil) }) | ||
} |