Skip to content

Commit

Permalink
Add couple more unit tests for util.go
Browse files Browse the repository at this point in the history
Signed-off-by: Rodolfo Olivieri <[email protected]>
  • Loading branch information
r0x0d committed Aug 11, 2023
1 parent 53989d9 commit 6de47cb
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,54 @@ func TestLoadConfigOrDefault(t *testing.T) {
})
}
}

func TestSetDefaultValues(t *testing.T) {
type args struct {
config *Config
}
tests := []struct {
name string
args args
want args
}{
{
name: "test default values",
args: args{config: &Config{nil, nil, nil, nil}},
want: args{config: &Config{strPtr("rhc-worker-script"), boolPtr(true), boolPtr(true), strPtr("/var/lib/rhc-worker-script")}},
},
{
name: "test non default values",
args: args{config: &Config{strPtr("rhc-worker-script"), boolPtr(true), boolPtr(true), strPtr("/var/lib/rhc-worker-script")}},
want: args{config: &Config{strPtr("rhc-worker-script"), boolPtr(true), boolPtr(true), strPtr("/var/lib/rhc-worker-script")}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
setDefaultValues(tt.args.config)

if !compareConfigs(tt.args.config, tt.want.config) {
t.Errorf("Loaded config does not match expected config")
}
})
}
}

func TestCheckAndCreateDirectory(t *testing.T) {
type args struct {
folder string
}
tests := []struct {
name string
args args
wantErr bool
}{
{name: "non existing path", args: args{folder: "/non-existing/path"}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := checkAndCreateDirectory(tt.args.folder); (err != nil) != tt.wantErr {
t.Errorf("checkAndCreateDirectory() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 6de47cb

Please sign in to comment.