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

test: add test for bare-metal deployer #125

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
status:
project: on
patch: on
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gtctl

[![codecov](https://codecov.io/github/GreptimeTeam/gtctl/branch/main/graph/badge.svg?token=287NUSEH5D)](https://codecov.io/github/GreptimeTeam/gtctl)
[![codecov](https://codecov.io/github/GreptimeTeam/gtctl/branch/develop/graph/badge.svg?token=287NUSEH5D)](https://app.codecov.io/github/GreptimeTeam/gtctl/tree/develop)

## Overview

Expand Down
99 changes: 99 additions & 0 deletions pkg/deployer/baremetal/deployer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2023 Greptime Team
//
// 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 baremetal

import (
"context"
"os"
"path"
"testing"

"github.com/stretchr/testify/assert"

"github.com/GreptimeTeam/gtctl/pkg/deployer/baremetal/component"
"github.com/GreptimeTeam/gtctl/pkg/deployer/baremetal/config"
"github.com/GreptimeTeam/gtctl/pkg/logger"
)

var L = logger.New(os.Stdout, 1, logger.WithColored())

func TestNewDeployer(t *testing.T) {
homedir, err := os.UserHomeDir()
shawnh2 marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, err)
clusterName := "test"

// New Deployer with no options
deployer, err := NewDeployer(L, clusterName)
assert.NoError(t, err)
d1, ok := deployer.(*Deployer)
assert.True(t, ok)
assert.NotNil(t, d1)
assert.Equal(t, d1.baseDir, path.Join(homedir, config.GtctlDir))
assert.Equal(t, d1.clusterDir, path.Join(homedir, config.GtctlDir, clusterName))
assert.Equal(t, d1.workingDirs, component.WorkingDirs{
DataDir: path.Join(homedir, config.GtctlDir, clusterName, "data"),
LogsDir: path.Join(homedir, config.GtctlDir, clusterName, "logs"),
PidsDir: path.Join(homedir, config.GtctlDir, clusterName, "pids"),
})
assert.False(t, d1.alwaysDownload)

// New Deployer with always download option
deployer, err = NewDeployer(L, clusterName, WithAlawaysDownload(true))
zyy17 marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, err)
d2, ok := deployer.(*Deployer)
assert.True(t, ok)
assert.NotNil(t, d2)
assert.True(t, d2.alwaysDownload)

// New Deployer with config option
newConfig := config.DefaultConfig()
newConfig.Cluster.Frontend.Replicas = 3
deployer, err = NewDeployer(L, clusterName, WithConfig(newConfig))
assert.NoError(t, err)
d3, ok := deployer.(*Deployer)
assert.True(t, ok)
assert.NotNil(t, d3)
assert.Equal(t, newConfig, d3.config)

// New Deployer with specific version
version := "foobar"
deployer, err = NewDeployer(L, clusterName, WithGreptimeVersion(version))
assert.NoError(t, err)
d4, ok := deployer.(*Deployer)
assert.True(t, ok)
assert.NotNil(t, d4)
assert.Equal(t, version, d4.config.Cluster.Artifact.Version)
}

func TestDeleteGreptimeClusterForeground(t *testing.T) {
clusterName := "test"

d, err := NewDeployer(L, clusterName)
assert.NoError(t, err)
deployer, ok := d.(*Deployer)
assert.True(t, ok)
assert.NotNil(t, deployer)

err = deployer.deleteGreptimeDBClusterForeground(context.Background(), component.DeleteOptions{})
assert.NoError(t, err)

info, err := os.Stat(deployer.clusterDir)
if os.IsExist(err) {
t.Errorf("cluster dir %s should not exist: %v", deployer.clusterDir, err)
}
if info != nil && !info.IsDir() {
t.Errorf("cluster dir %s is not a dir", deployer.clusterDir)
}
}
Loading