Skip to content

Commit

Permalink
[test] Marshal test added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Keser committed Aug 15, 2021
1 parent 7689c2d commit a0c5d05
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions domain/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"encoding/json"
`strings`
"testing"

`github.com/spf13/viper`
Expand Down Expand Up @@ -51,9 +52,9 @@ func TestCli_Load(t *testing.T) {

func TestCli_UnmarshalJSON(t *testing.T) {
type fields struct {
userAPIToken string
agentID string
DBConfig repository.Database
userAPIToken string
agentID string
DBConfig repository.Database
}
type args struct {
bytes []byte
Expand All @@ -67,9 +68,9 @@ func TestCli_UnmarshalJSON(t *testing.T) {
{
name: "testing bad cli object",
fields: fields{
userAPIToken: "bad_token",
agentID: "bad_id",
DBConfig: repository.Database{},
userAPIToken: "bad_token",
agentID: "bad_id",
DBConfig: repository.Database{},
},
args: args{
bytes: []byte(`{"user_api_token": "bad_token", "agent_id": "bad_id"}`),
Expand All @@ -79,8 +80,8 @@ func TestCli_UnmarshalJSON(t *testing.T) {
{
name: "testing worse cli object",
fields: fields{
userAPIToken: "bad_token",
agentID: "bad_id",
userAPIToken: "bad_token",
agentID: "bad_id",
},
args: args{
bytes: []byte(`"user_api_": "bad_token", "agent_id": "bad_id"}`),
Expand All @@ -102,10 +103,36 @@ func TestCli_UnmarshalJSON(t *testing.T) {
}
}

const testConfig = `
agent_id: ""
api_domain: api.strixeye.com
db_addr: 127.0.0.1
db_name: strixeye
db_override: true
db_pass: "sdsss"
db_port: ""
db_user: ""
docker_registry: docker.strixeye.com
download_domain: downloads.strixeye.com
pretty_output: false
user_api_token: ""`

func TestCli_MarshalJSON(t *testing.T) {
viper.SetConfigType("yaml")
_ = viper.ReadConfig(strings.NewReader(testConfig))
a := Cli{}
err := viper.Unmarshal(&a)
if err != nil{
t.Error(err)
return
}

}

func TestCli_Validate(t *testing.T) {
type fields struct {
userAPIToken string
agentID string
userAPIToken string
agentID string
}
tests := []struct {
name string
Expand All @@ -121,8 +148,8 @@ func TestCli_Validate(t *testing.T) {
}, {
name: "Good object",
fields: fields{
userAPIToken: "blah",
agentID: "blah",
userAPIToken: "blah",
agentID: "blah",
},
wantErr: false,
},
Expand All @@ -133,8 +160,8 @@ func TestCli_Validate(t *testing.T) {
t.Run(
tt.name, func(t *testing.T) {
c := &Cli{
UserAPIToken: tt.fields.userAPIToken,
AgentID: tt.fields.agentID,
UserAPIToken: tt.fields.userAPIToken,
AgentID: tt.fields.agentID,
}
if err := c.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -146,8 +173,8 @@ func TestCli_Validate(t *testing.T) {

func TestCli_Save(t *testing.T) {
type fields struct {
UserAPIToken string
agentID string
UserAPIToken string
agentID string
}
type args struct {
filePath string
Expand All @@ -174,8 +201,8 @@ func TestCli_Save(t *testing.T) {
t.Run(
tt.name, func(t *testing.T) {
c := &Cli{
UserAPIToken: tt.fields.UserAPIToken,
AgentID: tt.fields.agentID,
UserAPIToken: tt.fields.UserAPIToken,
AgentID: tt.fields.agentID,
}
if err := c.Save(tt.args.filePath); (err != nil) != tt.wantErr {
t.Errorf("Save() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit a0c5d05

Please sign in to comment.