Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase coverage #2551

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion operatorapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,5 @@ func getMarketplace() string {
// Get DirectPVMode
func getDirectPVEnabled() bool {
currentMode := env.Get(DirectPVMode, "off")

return currentMode == "on"
}
38 changes: 38 additions & 0 deletions operatorapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package operatorapi
import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_getK8sSAToken(t *testing.T) {
Expand Down Expand Up @@ -96,3 +98,39 @@ func Test_getMarketplace(t *testing.T) {
})
}
}

func Test_getDirectPVEnabled(t *testing.T) {
type args struct {
setEnv bool
}
tests := []struct {
name string
want bool
args args
}{
{
name: "DirectPV Mode is Set",
want: true,
args: args{
setEnv: true,
},
},
{
name: "DirectPV Mode is not set",
want: false,
args: args{
setEnv: false,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.args.setEnv {
os.Setenv(DirectPVMode, "on")
} else {
os.Unsetenv(DirectPVMode)
}
assert.Equalf(t, tt.want, getDirectPVEnabled(), "getDirectPVEnabled()")
})
}
}
110 changes: 110 additions & 0 deletions operatorapi/logs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// This file is part of MinIO Console Server
// Copyright (c) 2022 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package operatorapi

import (
"flag"
"fmt"
"testing"

"github.com/minio/cli"
"github.com/stretchr/testify/assert"
)

func TestContext_Load(t *testing.T) {
type fields struct {
Host string
HTTPPort int
HTTPSPort int
TLSRedirect string
TLSCertificate string
TLSKey string
TLSca string
}
type args struct {
values map[string]string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "valid args",
args: args{
values: map[string]string{
"tls-redirect": "on",
},
},
wantErr: false,
},
{
name: "invalid args",
args: args{
values: map[string]string{
"tls-redirect": "aaaa",
},
},
wantErr: true,
},
{
name: "invalid port http",
args: args{
values: map[string]string{
"tls-redirect": "on",
"port": "65536",
},
},
wantErr: true,
},
{
name: "invalid port https",
args: args{
values: map[string]string{
"tls-redirect": "on",
"port": "65534",
"tls-port": "65536",
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Context{}

fs := flag.NewFlagSet("flags", flag.ContinueOnError)
for k, v := range tt.args.values {
fs.String(k, v, "ok")
}

ctx := cli.NewContext(nil, fs, &cli.Context{})

err := c.Load(ctx)
if tt.wantErr {
assert.NotNilf(t, err, fmt.Sprintf("Load(%v)", err))
} else {
assert.Nilf(t, err, fmt.Sprintf("Load(%v)", err))
}
})
}
}

func Test_logInfo(t *testing.T) {
logInfo("message", nil)
}
52 changes: 52 additions & 0 deletions operatorapi/parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ package operatorapi

import (
"encoding/json"
"net/http"
"reflect"
"testing"

"github.com/minio/console/operatorapi/operations/operator_api"
"github.com/stretchr/testify/assert"

"github.com/minio/console/models"
)

Expand Down Expand Up @@ -77,3 +81,51 @@ func Test_getParityInfo(t *testing.T) {
})
}
}

func Test_getParityResponse(t *testing.T) {
type args struct {
params operator_api.GetParityParams
}
tests := []struct {
name string
args args
want models.ParityResponse
wantErr bool
}{
{
name: "valid",
args: args{
params: operator_api.GetParityParams{
HTTPRequest: &http.Request{},
DisksPerNode: 4,
Nodes: 4,
},
},
want: models.ParityResponse{"EC:8", "EC:7", "EC:6", "EC:5", "EC:4", "EC:3", "EC:2"},
wantErr: false,
},
{
name: "invalid",
args: args{
params: operator_api.GetParityParams{
HTTPRequest: &http.Request{},
DisksPerNode: -4,
Nodes: 4,
},
},
want: models.ParityResponse(nil),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := getParityResponse(tt.args.params)
assert.Equalf(t, tt.want, got, "getParityResponse(%v)", tt.args.params)
if tt.wantErr {
assert.NotNilf(t, got1, "getParityResponse(%v)", tt.args.params)
} else {
assert.Nilf(t, got1, "getParityResponse(%v)", tt.args.params)
}
})
}
}
24 changes: 24 additions & 0 deletions operatorapi/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,27 @@ func TestGenerateTenantConfigurationFile(t *testing.T) {
})
}
}

func Test_stringPtr(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
wantNil bool
}{
{
name: "get a pointer",
args: args{
str: "",
},
wantNil: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.NotNilf(t, stringPtr(tt.args.str), "stringPtr(%v)", tt.args.str)
})
}
}
1 change: 0 additions & 1 deletion restapi/client-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type MinioAdmin interface {
delConfigKV(ctx context.Context, kv string) (err error)
serviceRestart(ctx context.Context) error
serverInfo(ctx context.Context) (madmin.InfoMessage, error)

startProfiling(ctx context.Context, profiler madmin.ProfilerType) ([]madmin.StartProfilingResult, error)
stopProfiling(ctx context.Context) (io.ReadCloser, error)
serviceTrace(ctx context.Context, threshold int64, s3, internal, storage, os, errTrace bool) <-chan madmin.ServiceTraceInfo
Expand Down
Loading