Skip to content

Commit

Permalink
Add Unit Tests for Kopia (#1723)
Browse files Browse the repository at this point in the history
* Add Unit Test For Blob Commands

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add Unit Test For Blob Commands

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Rearrange Imports

* Add Constants

* Add Unit Tests for maintenance.go

* Add Unit Tests for parse_command_output.go

* Add Unit Tests for policy_set_global.go

* Add Unit Tests for restore.go

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Updates

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add unit test for server.go

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Added Unit Test for snapshot.go

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Added Unit Test for get_maintenance_owner.go

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Added github.com/frankban/quicktest in go.mod

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add Unit Test for repository.go

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Update Tests

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Fix Linting Problems

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Fix Failing Unit Test Problems

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Replace Dependencies

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Use testing and gocheck instead of quicktest for UT

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Resolve Conflict --> Update go.mod and go.sum

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add Newline in go.sum

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
  • Loading branch information
r4rajat committed Nov 21, 2022
1 parent 8908b5b commit c31f4be
Show file tree
Hide file tree
Showing 12 changed files with 1,219 additions and 6 deletions.
64 changes: 64 additions & 0 deletions pkg/kopia/command/blob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2022 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package command

import (
"strings"
"testing"

. "gopkg.in/check.v1"
)

// Hook up gocheck into the "go test" runner.
func TestKopiaCommandWrappers(t *testing.T) { TestingT(t) }

type KopiaBlobTestSuite struct{}

var _ = Suite(&KopiaBlobTestSuite{})

func (kBlob *KopiaBlobTestSuite) TestBlobCommands(c *C) {
commandArgs := &CommandArgs{
RepoPassword: "encr-key",
ConfigFilePath: "path/kopia.config",
LogDirectory: "cache/log",
}

for _, tc := range []struct {
f func() []string
expectedLog string
}{
{
f: func() []string {
args := BlobListCommandArgs{
CommandArgs: commandArgs,
}
return BlobList(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key blob list",
},
{
f: func() []string {
args := BlobStatsCommandArgs{
CommandArgs: commandArgs,
}
return BlobStats(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key blob stats --raw",
},
} {
cmd := strings.Join(tc.f(), " ")
c.Assert(cmd, Equals, tc.expectedLog)
}
}
12 changes: 12 additions & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ const (

// Repository specific
repositorySubCommand = "repository"

// DefaultCacheDirectory is the directory where kopia content cache is created
DefaultCacheDirectory = "/tmp/kopia-cache"

// DefaultConfigFilePath is the file which contains kopia repo config
DefaultConfigFilePath = "/tmp/kopia-repository.config"

// DefaultConfigDirectory is the directory which contains custom kopia repo config
DefaultConfigDirectory = "/tmp/kopia-repository"

// DefaultLogDirectory is the directory where kopia log file is created
DefaultLogDirectory = "/tmp/kopia-log"
)
81 changes: 81 additions & 0 deletions pkg/kopia/command/maintenance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2022 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package command

import (
"strings"

. "gopkg.in/check.v1"
)

type KopiaMaintenanceTestSuite struct{}

var _ = Suite(&KopiaMaintenanceTestSuite{})

func (kMaintenance *KopiaMaintenanceTestSuite) TestMaintenanceCommands(c *C) {
commandArgs := &CommandArgs{
RepoPassword: "encr-key",
ConfigFilePath: "path/kopia.config",
LogDirectory: "cache/log",
}

for _, tc := range []struct {
f func() []string
expectedLog string
}{
{
f: func() []string {
args := MaintenanceInfoCommandArgs{
CommandArgs: commandArgs,
GetJsonOutput: false,
}
return MaintenanceInfo(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key maintenance info",
},
{
f: func() []string {
args := MaintenanceInfoCommandArgs{
CommandArgs: commandArgs,
GetJsonOutput: true,
}
return MaintenanceInfo(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key maintenance info --json",
},
{
f: func() []string {
args := MaintenanceSetOwnerCommandArgs{
CommandArgs: commandArgs,
CustomOwner: "username@hostname",
}
return MaintenanceSetOwner(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key maintenance set --owner=username@hostname",
},
{
f: func() []string {
args := MaintenanceRunCommandArgs{
CommandArgs: commandArgs,
}
return MaintenanceRunCommand(args)
},
expectedLog: "kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log --password=encr-key maintenance run",
},
} {
cmd := strings.Join(tc.f(), " ")
c.Check(cmd, Equals, tc.expectedLog)
}
}
Loading

0 comments on commit c31f4be

Please sign in to comment.