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 alias test #540

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions cmd/alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

import (
"io/ioutil"
"os"
"testing"
)

func Test_updateFile(t *testing.T) {
testFile, _ := ioutil.TempFile("", "")
defer os.Remove(testFile.Name())
type args struct {
cxt string
path string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test",
args: args{
cxt: "test",
path: testFile.Name(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := updateFile(tt.args.cxt, tt.args.path); (err != nil) != tt.wantErr {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
file, err := os.ReadFile(tt.args.path)
if err != nil {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
if string(file) != tt.args.cxt {
t.Errorf("updateFile() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func Test_writeAppend(t *testing.T) {
bashFile, _ := ioutil.TempFile("", ".bash")
defer os.Remove(bashFile.Name())
type args struct {
context string
path string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test",
args: args{
context: "test",
path: bashFile.Name(),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := writeAppend(tt.args.context, tt.args.path); (err != nil) != tt.wantErr {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
file, err := os.ReadFile(tt.args.path)
if err != nil {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
if string(file) != tt.args.context+"\n" {
t.Errorf("writeAppend() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}