Skip to content

Commit

Permalink
change test_readsshhostkeypublicfiles "line" args struct field to "co…
Browse files Browse the repository at this point in the history
…ntent"

This aims to make the test more obvious that this is the content going into the temporary file
  • Loading branch information
Xeckt committed Jun 21, 2024
1 parent 8cad627 commit 2655c0e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions sztp-agent/pkg/secureagent/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_linesInFileContains(t *testing.T) {
func Test_readSSHHostKeyPublicFiles(t *testing.T) {
type args struct {
file string
line string
content string
keyType string
}
tests := []struct {
Expand All @@ -138,7 +138,7 @@ func Test_readSSHHostKeyPublicFiles(t *testing.T) {
name: "Test OK line in files no comment",
args: args{
file: "/tmp/test.pub",
line: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR",
content: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR",
keyType: "ssh-ed25519",
},
want: []publicKey{{Type: "ssh-ed25519", Data: "AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR"}},
Expand All @@ -147,7 +147,7 @@ func Test_readSSHHostKeyPublicFiles(t *testing.T) {
name: "Test OK line in files with comment",
args: args{
file: "/tmp/test.pub",
line: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR comment",
content: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR comment",
keyType: "ssh-ed25519",
},
want: []publicKey{{Type: "ssh-ed25519", Data: "AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR"}},
Expand All @@ -156,32 +156,32 @@ func Test_readSSHHostKeyPublicFiles(t *testing.T) {
name: "Test too many parts in file",
args: args{
file: "/tmp/test.pub",
line: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR comment error",
content: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR comment error",
keyType: "ssh-ed25519",
},
want: []publicKey{{Type: "ssh-ed25519", Data: "AAAAC3NzaC1lZDI1NTE5AAAAID0mjQXlOvkM2HO5vTrSOdHOl3BGOqDiHrx8yYdbP8xR"}},
},
{
name: "Test not enough parts in file",
args: args{
file: "/tmp/test.pub",
line: "ssh-ed25519",
file: "/tmp/test.pub",
content: "ssh-ed25519",
},
want: []publicKey{},
},
{
name: "Test file doesn't exist",
args: args{
file: "/tmp/test.pub",
line: "",
file: "/tmp/test.pub",
content: "",
},
want: []publicKey{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.args.line != "" {
createTempTestFile(tt.args.file, tt.args.line, true)
if tt.args.content != "" {
createTempTestFile(tt.args.file, tt.args.content, true)
}
if got := readSSHHostKeyPublicFiles(tt.args.file); !reflect.DeepEqual(got, tt.want) {
t.Errorf("readSSHHostKeyPublicFiles() = %v, want %v", got, tt.want)
Expand Down

0 comments on commit 2655c0e

Please sign in to comment.