Skip to content

Commit 1cb2fca

Browse files
authored
Increase coverage (#2551)
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
1 parent 287af26 commit 1cb2fca

File tree

9 files changed

+800
-2
lines changed

9 files changed

+800
-2
lines changed

operatorapi/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,5 @@ func getMarketplace() string {
7373
// Get DirectPVMode
7474
func getDirectPVEnabled() bool {
7575
currentMode := env.Get(DirectPVMode, "off")
76-
7776
return currentMode == "on"
7877
}

operatorapi/config_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package operatorapi
1919
import (
2020
"os"
2121
"testing"
22+
23+
"github.com/stretchr/testify/assert"
2224
)
2325

2426
func Test_getK8sSAToken(t *testing.T) {
@@ -96,3 +98,39 @@ func Test_getMarketplace(t *testing.T) {
9698
})
9799
}
98100
}
101+
102+
func Test_getDirectPVEnabled(t *testing.T) {
103+
type args struct {
104+
setEnv bool
105+
}
106+
tests := []struct {
107+
name string
108+
want bool
109+
args args
110+
}{
111+
{
112+
name: "DirectPV Mode is Set",
113+
want: true,
114+
args: args{
115+
setEnv: true,
116+
},
117+
},
118+
{
119+
name: "DirectPV Mode is not set",
120+
want: false,
121+
args: args{
122+
setEnv: false,
123+
},
124+
},
125+
}
126+
for _, tt := range tests {
127+
t.Run(tt.name, func(t *testing.T) {
128+
if tt.args.setEnv {
129+
os.Setenv(DirectPVMode, "on")
130+
} else {
131+
os.Unsetenv(DirectPVMode)
132+
}
133+
assert.Equalf(t, tt.want, getDirectPVEnabled(), "getDirectPVEnabled()")
134+
})
135+
}
136+
}

operatorapi/logs_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2022 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package operatorapi
18+
19+
import (
20+
"flag"
21+
"fmt"
22+
"testing"
23+
24+
"github.com/minio/cli"
25+
"github.com/stretchr/testify/assert"
26+
)
27+
28+
func TestContext_Load(t *testing.T) {
29+
type fields struct {
30+
Host string
31+
HTTPPort int
32+
HTTPSPort int
33+
TLSRedirect string
34+
TLSCertificate string
35+
TLSKey string
36+
TLSca string
37+
}
38+
type args struct {
39+
values map[string]string
40+
}
41+
tests := []struct {
42+
name string
43+
fields fields
44+
args args
45+
wantErr bool
46+
}{
47+
{
48+
name: "valid args",
49+
args: args{
50+
values: map[string]string{
51+
"tls-redirect": "on",
52+
},
53+
},
54+
wantErr: false,
55+
},
56+
{
57+
name: "invalid args",
58+
args: args{
59+
values: map[string]string{
60+
"tls-redirect": "aaaa",
61+
},
62+
},
63+
wantErr: true,
64+
},
65+
{
66+
name: "invalid port http",
67+
args: args{
68+
values: map[string]string{
69+
"tls-redirect": "on",
70+
"port": "65536",
71+
},
72+
},
73+
wantErr: true,
74+
},
75+
{
76+
name: "invalid port https",
77+
args: args{
78+
values: map[string]string{
79+
"tls-redirect": "on",
80+
"port": "65534",
81+
"tls-port": "65536",
82+
},
83+
},
84+
wantErr: true,
85+
},
86+
}
87+
for _, tt := range tests {
88+
t.Run(tt.name, func(t *testing.T) {
89+
c := &Context{}
90+
91+
fs := flag.NewFlagSet("flags", flag.ContinueOnError)
92+
for k, v := range tt.args.values {
93+
fs.String(k, v, "ok")
94+
}
95+
96+
ctx := cli.NewContext(nil, fs, &cli.Context{})
97+
98+
err := c.Load(ctx)
99+
if tt.wantErr {
100+
assert.NotNilf(t, err, fmt.Sprintf("Load(%v)", err))
101+
} else {
102+
assert.Nilf(t, err, fmt.Sprintf("Load(%v)", err))
103+
}
104+
})
105+
}
106+
}
107+
108+
func Test_logInfo(t *testing.T) {
109+
logInfo("message", nil)
110+
}

operatorapi/parity_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ package operatorapi
1818

1919
import (
2020
"encoding/json"
21+
"net/http"
2122
"reflect"
2223
"testing"
2324

25+
"github.com/minio/console/operatorapi/operations/operator_api"
26+
"github.com/stretchr/testify/assert"
27+
2428
"github.com/minio/console/models"
2529
)
2630

@@ -77,3 +81,51 @@ func Test_getParityInfo(t *testing.T) {
7781
})
7882
}
7983
}
84+
85+
func Test_getParityResponse(t *testing.T) {
86+
type args struct {
87+
params operator_api.GetParityParams
88+
}
89+
tests := []struct {
90+
name string
91+
args args
92+
want models.ParityResponse
93+
wantErr bool
94+
}{
95+
{
96+
name: "valid",
97+
args: args{
98+
params: operator_api.GetParityParams{
99+
HTTPRequest: &http.Request{},
100+
DisksPerNode: 4,
101+
Nodes: 4,
102+
},
103+
},
104+
want: models.ParityResponse{"EC:8", "EC:7", "EC:6", "EC:5", "EC:4", "EC:3", "EC:2"},
105+
wantErr: false,
106+
},
107+
{
108+
name: "invalid",
109+
args: args{
110+
params: operator_api.GetParityParams{
111+
HTTPRequest: &http.Request{},
112+
DisksPerNode: -4,
113+
Nodes: 4,
114+
},
115+
},
116+
want: models.ParityResponse(nil),
117+
wantErr: true,
118+
},
119+
}
120+
for _, tt := range tests {
121+
t.Run(tt.name, func(t *testing.T) {
122+
got, got1 := getParityResponse(tt.args.params)
123+
assert.Equalf(t, tt.want, got, "getParityResponse(%v)", tt.args.params)
124+
if tt.wantErr {
125+
assert.NotNilf(t, got1, "getParityResponse(%v)", tt.args.params)
126+
} else {
127+
assert.Nilf(t, got1, "getParityResponse(%v)", tt.args.params)
128+
}
129+
})
130+
}
131+
}

operatorapi/utils_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,27 @@ func TestGenerateTenantConfigurationFile(t *testing.T) {
228228
})
229229
}
230230
}
231+
232+
func Test_stringPtr(t *testing.T) {
233+
type args struct {
234+
str string
235+
}
236+
tests := []struct {
237+
name string
238+
args args
239+
wantNil bool
240+
}{
241+
{
242+
name: "get a pointer",
243+
args: args{
244+
str: "",
245+
},
246+
wantNil: false,
247+
},
248+
}
249+
for _, tt := range tests {
250+
t.Run(tt.name, func(t *testing.T) {
251+
assert.NotNilf(t, stringPtr(tt.args.str), "stringPtr(%v)", tt.args.str)
252+
})
253+
}
254+
}

restapi/client-admin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ type MinioAdmin interface {
8787
delConfigKV(ctx context.Context, kv string) (err error)
8888
serviceRestart(ctx context.Context) error
8989
serverInfo(ctx context.Context) (madmin.InfoMessage, error)
90-
9190
startProfiling(ctx context.Context, profiler madmin.ProfilerType) ([]madmin.StartProfilingResult, error)
9291
stopProfiling(ctx context.Context) (io.ReadCloser, error)
9392
serviceTrace(ctx context.Context, threshold int64, s3, internal, storage, os, errTrace bool) <-chan madmin.ServiceTraceInfo

0 commit comments

Comments
 (0)